问题
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