How do I prevent my keyboard to open when I'm selecting text from edit text? I want the text inside to be still selectable, while not opening the keyboard when I click it
<EditText
android:id="@+id/displayalllinks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10" >
editText = (EditText) findViewById(R.id.editText_1);
boolean disabled = false;
//We listen for selection
editText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEvent.ACTION_UP == event.getAction()) {
//When selected, we disable input.
if (editText.hasSelection()) {
editText.setInputType(InputType.TYPE_NULL);
disabled = true;
} else
//Then we restore it, if previously unset.
if (disabled) {
editText.setInputType(TYPE_CLASS_TEXT);
disabled = false;
}
return false;
}
});
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With