Hide softkeyboard in single activity - Android

三世轮回 提交于 2019-12-23 05:14:06

问题


I have been searching the 'net for a bit here, I can't seem to stop the SoftKeyboard from appearing when an EditText gets focus, I've tried at least 3 different methods, setting the Input Type to None (think I saw that in the Android Dev Docs), and two different ways inside the onCreate method, they are:

getWindow().requestFeature(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

And

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

I know I can disable it for the entire app in the manifest file, but I only need it disabled in this activity.


回答1:


Nothing to do more just place below code in your manifest.xml for perticular activity...

android:configChanges="orientation|keyboardHidden" android:windowSoftInputMode="adjustResize|stateHidden"




回答2:


There is a bug in Android 2.0 and 2.1 that prevents the methods I attempted from working, but as written here this can be resolved. I didn't try the above methods, they might also work, but I did try the one I linked to, and it works.




回答3:


for this one whenever u want key board at that only u write soft keyboard appear,likebelow code

EditText EditTextName=findViewById(R.id.EditText01);
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(EditTextName), 0);

In above code i am enable the keyboard when edittext has focus.In the same way u disable the keyboard using

((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInput(EditTextName), 0);


来源:https://stackoverflow.com/questions/4769307/hide-softkeyboard-in-single-activity-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!