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.
Related
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);
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.
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.
I have this recurring issue with the onCreateOptionsMenu method. I have it set up so it enables or disables options depending on the value of some SharedPreferences, but for some reason the first time you open the menu it doesn't work as it should, the options that should be disabled are enabled and the other way around. If I close it and reopen it, it works fine.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
menuConfig(menu);
return true;
}
#Override
public boolean onPrepareOptionsMenu (Menu menu) {
menuConfig(menu);
return true;
}
public void menuConfig(Menu menu){
menu.getItem(getResources().getInteger(R.integer.MENU_ABOUT)).setEnabled(true);
if (preferences.getBoolean(getString(R.string.PREFS_STARTED), false)){
menu.getItem(getResources().getInteger(R.integer.MENU_START)).setEnabled(false);
menu.getItem(getResources().getInteger(R.integer.MENU_STOP)).setEnabled(true);
}else{
menu.getItem(getResources().getInteger(R.integer.MENU_START)).setEnabled(true);
menu.getItem(getResources().getInteger(R.integer.MENU_STOP)).setEnabled(false);
}
if(!preferences.getBoolean(getString(R.string.PREFS_STARTED),false) && preferences.getBoolean(getString(R.string.PREFS_FILES_CREATED),false)){
menu.getItem(getResources().getInteger(R.integer.MENU_DELETE)).setEnabled(true);
menu.getItem(getResources().getInteger(R.integer.MENU_SET_ID)).setEnabled(true);
}
else{
menu.getItem(getResources().getInteger(R.integer.MENU_DELETE)).setEnabled(false);
menu.getItem(getResources().getInteger(R.integer.MENU_SET_ID)).setEnabled(false);
}
}
These two pics are taken subsequently with a few seconds between each menu key press.
The first one is wrong, it should look like the second one.
I fixed it by changing the default value returned by the queries to the SharedPreferences object but I have no idea of what is actually happening.
We have this default feature in android 3.0 that when we long press somewhere (say in a webview) action mode is started and as a result the action bar changes with many default features like copy, find etc.
Now what I want is that I want to start this action mode but not by long pressing on the web view. I want that when I load a webview I want this action mode automatically started without any long press. Is it possible ? Is there any method by which we can achieve this?
In case you still need it or other people are looking for it
startActionMode(mContentSelectionActionModeCallback);
And as callback use:
private ActionMode.Callback mContentSelectionActionModeCallback =
new ActionMode.Callback() {
public boolean onCreateActionMode(ActionMode actionMode, Menu menu)
{
//Here you can inflate a menu
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.name_menu, menu);
return true;
}
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
return false;
}
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem)
{
return false;
}
public void onDestroyActionMode(ActionMode actionMode) {
awesomeAdapter.overviewFragment.stopEdit();
}
};