How to hide Android soft keyboard on EditText

前端 未结 16 1111
长发绾君心
长发绾君心 2020-11-27 14:38

I have an Activity with some EditText fields and some buttons as a convenience for what normally would be used to populate those fields. However when we the user touches on

相关标签:
16条回答
  • 2020-11-27 15:04
       public class NonKeyboardEditText extends AppCompatEditText {
    
        public NonKeyboardEditText(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        public boolean onCheckIsTextEditor() {
            return false;
        }
    }
    

    and add

    NonKeyboardEditText.setTextIsSelectable(true);
    
    0 讨论(0)
  • 2020-11-27 15:05

    The soft keyboard kept rising even though I set EditorInfo.TYPE_NULL to the view. None of the answers worked for me, except the idea I got from nik431's answer:

    editText.setCursorVisible(false);
    editText.setFocusableInTouchMode(false);
    editText.setFocusable(false);
    
    0 讨论(0)
  • 2020-11-27 15:05

    Let's try to set the below properties in your xml for EditText

    android:focusableInTouchMode="true" android:cursorVisible="false".
    

    if you want to hide the softkeypad at launching activity please go through this link

    0 讨论(0)
  • 2020-11-27 15:05

    Simply Use EditText.setFocusable(false); in activity

    or use in xml

    android:focusable="false"
    
    0 讨论(0)
  • 2020-11-27 15:07

    My test result:

    with setInputType:

    editText.setInputType(InputType.TYPE_NULL);
    

    the soft keyboard disappears, but the cursor will also disappear.

    with setShowSoftInputOnFocus:

    editText.setShowSoftInputOnFocus(false)
    

    It works as expected.

    0 讨论(0)
  • 2020-11-27 15:09
    weekText = (EditText) layout.findViewById(R.id.weekEditText);
    weekText.setInputType(InputType.TYPE_NULL);
    
    0 讨论(0)
提交回复
热议问题