Android Hide Soft Keyboard from EditText while not losing cursor

前端 未结 14 1908
日久生厌
日久生厌 2020-12-03 04:55

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 Buttons to enter a numb

14条回答
  •  失恋的感觉
    2020-12-03 05:35

    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:

    
    

    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

提交回复
热议问题