-1

I have an login fragment. For password (Edittext), I need to disable the Paste and select ALL options.

I tried setCustomSelectionActionModeCallback and "set longClickable " but they are not working. Any suggestions Thanks in advance

Swanand
  • 4,027
  • 10
  • 41
  • 69
sudheer
  • 19
  • 1

2 Answers2

1
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;
            }
        });

Returning false from onCreateActionMode(ActionMode, Menu) will prevent the action mode from being started(Select All, Cut, Copy and Paste actions).

Shanto George
  • 994
  • 13
  • 26
  • 1
    it is not working like this i tried ,functionality of select all not working and still it is displaying on double tap ,but i need not to show menu paste and selectAll in whole app wise how to do it. – sudheer Mar 15 '17 at 04:22
0

This will definitely work
All you need to do is add mode.finish() in onCreateActionMode()

mEntryText.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) {

        /* This is done to solve the issue of SELECT ALL PASTE etc., showing up.
         mode.finish() should not be called at this point. If called, it will throw
         this exception "E/DecorView[]: Destroying unexpected ActionMode instance of TYPE_FLOATING;
         com.android.internal.view.FloatingActionMode@2e022bc was not the current floating action mode! Expected null"
         This makes that class not to execute the rest of the code and hence the FloatingAction is never created!
         I wish the the author of FloatingActionMode class gave me a method to just stop showing it. menu.clear()
         is supposed to do it, but doesn't do.
         */

            mode.finish();  // menu.close(); menu.clear();
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; }
    });
Vikram
  • 1
  • 1