Search code examples
javaandroidandroid-keypad

How to disable software keyboard in EditText view and make cursor visible at same time in Android 4.0+?


How to disable software keyboard in EditText view and make cursor visible at same time?

I try all examples on stackoverflow and get two cases:

1. keyboard is hidden, cursor is hidden

2. keyboard is showing, cursor is showing

But I need keyboard hidden and cursor showing. How do it?

I do next:

dialText.setOnFocusChangeListener(new OnFocusChangeListener() {

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(dialText.getWindowToken(), 0);

    }
});

dialText.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(dialText.getWindowToken(), 0);
        return false;
    }
});

And keyboard still not hidden, when I moving cursor, keyboard is appearing again.

This issue is only on Android version 4.0+.


Solution

  • Use this in your manifest file in activity tag:

    <activity
            android:name=".ExampleActivity"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar" 
            android:windowSoftInputMode="stateHidden">
    </activity>