I\'ve come about as far as this which gets me halfway there, but not quite.
I have a dialer Fragment
that has all the usual Button
s to enter a numb
If your min SDK is 21, you can this method from java code:
editText.setShowSoftInputOnFocus(false);
Credits to Chen Su article.
The exact functionality that you require is provided by setting the flag textIsSelectable
in EditText to true. With this, the cursor will still be present, and you'll be able to select/copy/cut/paste, but SoftKeyboard will never show. Requires API 11 and above.
You can set it in your xml layout like this:
<EditText
android:textIsSelectable="true"
...
/>
Or programmatically, like this:
EditText editText = (EditText) findViewById(R.id.editText);
editText.setTextIsSelectable(true);
For anyone using API 10 and below, hack is provided here : https://stackoverflow.com/a/20173020/7550472
Setting the flag textIsSelectable to true disables the soft keyboard.
You can set it in your xml layout like this:
<EditText
android:id="@+id/editText"
...
android:textIsSelectable="true"/>
Or programmatically, like this:
EditText editText = (EditText) findViewById(R.id.editText);
editText.setTextIsSelectable(true);
The cursor will still be present, you'll be able to select/copy/cut/paste but the soft keyboard will never show.
This works perfectly (for me) in 2 steps:
<activity... android:windowSoftInputMode="stateHidden">
in manifest file
Add these properties in your editText XML code
android:focusable="true"
android:focusableInTouchMode="true
You have to put both 1 and 2, only then it will work.
Cheers
First add android:windowSoftInputMode="stateHidden"
in your manifest file, under the activity. like this
<activity... android:windowSoftInputMode="stateHidden">
The on your xml add this android:textIsSelectable="true"
. This will make the pointer visible.
Then on onCreate method of the activity, add this:
EditText editText = (EditText)findViewById(R.id.edit_text);
edit_text.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.onTouchEvent(event);
InputMethodManager inputMethod = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethod!= null) {
inputMethod.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
return true;
}
});
Best solution from @Lupsaa here:
Setting the flag textIsSelectable to true disables the soft keyboard.
You can set it in your xml layout like this:
<EditText
android:id="@+id/editText"
...
android:textIsSelectable="true"/>
Or programmatically, like this:
EditText editText = (EditText) findViewById(R.id.editText);
editText.setTextIsSelectable(true);
The cursor will still be present, you'll be able to select/copy/cut/paste but the soft keyboard will never show.