How to disable Android Soft Keyboard for a particular activity?

风格不统一 提交于 2019-12-03 06:18:01
Gligor

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.

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.

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.

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.

Willy Lin

You can try this. It is working for me:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
                     WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

you can use This Code:

<EditText
    .
    .
    android:enabled="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:inputType="numberPassword" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!