I am using following code but it is not working when cursor blink and I click on that paste button display.
edittext.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
public void onDestroyActionMode(ActionMode mode) {
}
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
});
I don't want to hide Cursor.
How do I solve this issue?
Try this:
edittext.setLongClickable(false);
edittext.setTextIsSelectable(false);
You can use longClickable in xml file like:
<EditText
... your edittext
android:longClickable = "false"/>
or you can try in java like
youredittext.setLongClickable(false);
you can try this just make your editext LongClickable false like below code
from XML
android:longClickable="false"
from JAVA
edittext.setLongClickable(false);
Related
This question already has answers here:
Disable EditText context menu
(7 answers)
Closed 5 years ago.
I am using EditText in my Android application. When i long press on the EditText, i want to remove/hide all the default context menu like Copy,Cut,Select All etc. Only paste menu should be shown. I have tried with the solution in the below link, but along with Paste, SelectAll option is also showing. How can i remove it.
EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event
EditText yourEditText = (EditText) findViewById(R.id.your_edit_text);
yourEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback()
{
#Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu)
{
return false;
}
#Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu)
{
return false;
}
#Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem)
{
return false;
}
#Override
public void onDestroyActionMode(ActionMode actionMode)
{
// Do your stuff here when you destroy
}
});
}
In your xml file, add following line to your respective editText:
android:textIsSelectable="false"
For further operations you can use that library:
https://github.com/neopixl/PixlUI
I want to disable copy paste in all of my android page and no one cant long touch on my application .
android:longClickable="false" it dosent work.
This worked for me:
In xml, disable the long-click in the EditText:
android:longClickable="false".
Also, you have to return false from these methods:
mEditEext.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
public void onDestroyActionMode(ActionMode mode) {
}
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
});
I think it will work fine. User can not able to copy your page to another app.
//Inside onResume and onDestroy
ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboardManager.setText("");
Here, It will restrict for background process "Secondary app". But you can copy and paste it only inside your app.
I have set CustomSelectionActionModeCallback to an edittext as below
new ActionMode.Callback() {
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
#Override
public void onDestroyActionMode(ActionMode mode) {
}
};
to disable paste option on edittext,but still user can paste by tapping on the cursor .I tried to create custom edittext class and override canPaste(),but still no luck.Can anybody suggest a correct solution.
Thanks.
Apparently the problem is observed in lollipop+ devices only
Another method one would suggest is to call setLongClickable(false) on the EditText, although that still doesn't prevent pasting from tapping on the cursor.
The proper (or only :) way to do this is to create a custom EditText and override isSuggestionsEnabled and canPaste methods.
Check this answer for an example.
this is my app strategy:
there is a text view that contains texts.
for editing them, i define Action mode items(e.g. EDIT- this will
texts of text view into edit text)although there are some default
actions like select all/copy/.. as selecting text, so i don not want
to define them.
i use this code for enabling the default selecting/copy buttons.
but as i clicked the buttons, nothing happens. why???
xml code:
<TextView
android:id="#+id/speech"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="30dp"
android:textSize="25sp" android:textAlignment="inherit"
android:selectAllOnFocus="true"
android:background="#drawable/curved_background"
android:layout_centerInParent="true" android:textIsSelectable="true"
android:padding="10dp" />
initializing TextView in class:
speech_text = (TextView) findViewById(R.id.speech);
registerForContextMenu(speech_text);
speech_text.setTextIsSelectable(true);
speech_text.setCustomSelectionActionModeCallback(new SelectText());
SelectingText java class:
public class SelectText implements ActionMode.Callback {
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.text_select, menu);
return true;
}
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Log.d(Log, String.format("onActionItemClicked item=%s/%d", item.toString(), item.getItemId()));
switch (item.getItemId()) {
case ... //other actions
return true;
}
return true;
}
#Override
public void onDestroyActionMode(ActionMode mode) {
}
}
Note:
as i control my code. the problem is in defining SelectText class in this line: speech_text.setCustomSelectionActionModeCallback(new SelectText()); because as i delete thiscode, every thing worksgood!
You can make your text in app enable for copy/paste in clipboard by adding below line :
android:textIsSelectable
For more information, Please check below reference,
http://developer.android.com/reference/android/widget/TextView.html
Thanks.
This should work for you.
In your xml jus make sure that....
android:focusable="true"
android:textIsSelectable="true"
I trying to create a note apps that have an ability to format the selected text in EditText like the one I usually use in Onenote. But everytime I click my menu icon, the selected text in EditText is resetted and the menu is closed itself.
This is my code in my custom Edit Text
public void init()
{
this.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.edit_text_menu, menu);
return true;
}
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return true;
}
#Override
public void onDestroyActionMode(ActionMode mode) {
}
});
}
Menu Layout
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_bold"
android:title="Bold"/>
<item android:id="#+id/action_underline"
android:title="Underline"/>
<item android:id="#+id/action_italic"
android:title="Italic"/>
</menu>
the screenshot of onenote menu
http://i57.tinypic.com/zlriu9.png
and screenshot of my apps
http://i58.tinypic.com/2yjwlys.jpg
What is the right way to make a menu for EditText to format just the selected text?
Update! Already found a solution that I think work this far
I just need to override the onWindowFocusChanged function, so when I click another menu, it won't lose its selection.