How to disable Android Soft Keyboard for a particular activity?

后端 未结 6 1749
南旧
南旧 2021-02-08 11:03

I have an activity with one EditText where I need to input numbers only.

Now, I have defined the Input Type for my EditText to be number only and have drawn up a pretty

相关标签:
6条回答
  • 2021-02-08 11:45

    You can try this. It is working for me:

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
                         WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    
    0 讨论(0)
  • 2021-02-08 11:48

    you can use This Code:

    <EditText
        .
        .
        android:enabled="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:inputType="numberPassword" />
    
    0 讨论(0)
  • 2021-02-08 11:51

    Just thought it might be possible to extend EditText and handle the access to the softkeyboard through there and came across this question which has a very elegant solution to my problem.

    Just followed the steps and this handled the softkeyboard perfectly for me. Hope it helps others that come across this issue.

    0 讨论(0)
  • 2021-02-08 11:55

    In Whichever Edittext you need to disable the soft keyboard, add attribute in xml of that edit text.

    <EditText android:id=".."
              ..
              android:focusable="false" />
    

    It will stop the execution of soft keyboard.

    0 讨论(0)
  • 2021-02-08 12:01

    Use the android:windowSoftInputMode="stateHidden" in your activity in manifest file. This will work. Don't use the android:focusable="false" for EditText unless if you are not willing to input the text. If you want to give input then remove that property for the edittext in the layout file.

    0 讨论(0)
  • 2021-02-08 12:02

    If you are using for example ViewGroup it allows you to block the soft keyboard using this method:

    view.setDescendantFocusability(view.FOCUS_BLOCK_DESCENDANTS);
    

    Thanks to this the view will get focus before any of its descendants.

    0 讨论(0)
提交回复
热议问题