0

I have an EditText et. When I want to modify its text, the android soft keyboard pops up.
The problem is that in some devices, the cut, copy and print button are all on top bar and due to the fact that the keyboard pops up while I am modifying the text in EditBox, I cant copy and paste in those devices. (Its a ListView and it is not scrollable)
The option that easily solves my problem is to close the soft keyboard once my text in et is selected. I have searched a lot but I couldn't find any listener for this. Is there any solution to this issue?
I understand that I can write my own ActionMode but I don't want to rewrite the android's default copy/paste bar.
I also tried to use setOnLongClickListener() on et but for some reasons it's not trigered when I select the text.

et.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
            Toast.makeText(ProfileActivity.this, "text is selected", Toast.LENGTH_LONG).show();
            return true;
        }
    });
abeikverdi
  • 1,216
  • 3
  • 13
  • 25

1 Answers1

0

For this you have to add some property in edittext of your xml file.

set your EditText to be selectable (android:textIsSelectable="true" or      
setTextIsSelectable(true);
Implement the ActionMode.Callback interface and provide your own menu items.

check below links,they might helps you-

link1

link2

link3

Community
  • 1
  • 1
Ravi Bhandari
  • 4,682
  • 8
  • 40
  • 68