I click a button and launch an activity with a soft keyboard:
When I click on the Cancel button, it calls finish() to exit to the first page. Then when I launch the activity again i get this:
The layout with the buttons is now hidden behind the keyboard.
In another scenario if i do it this way:
I get picture 1. The buttons don't get hidden. Seems like I have to destroy the keyboard before calling finish().
How do I solve this problem?
Edit: Added example of what's in the Manifest
<activity
android:name=".SignUp"
android:theme="@style/DefaultTitle" />
This is in my manifest as well, I added it after reading some other posts, didn't work for me.
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="7" />
Ok LOL. Weird discovery. If I do this:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(cancel.getApplicationWindowToken(), 0);
try {
Thread.sleep(100);
} catch (Exception e) {
}
finish();
it works! Not sure if this is a good workaround....
Put this line in your activity tag and let me know what happen,
<activity android:windowSoftInputMode="stateVisible" . . . >
For more info look at android:windowSoftInputMode
I think you are showing the SoftKeyBoard Using STATE_ALWAYS_VISIBLE
Thats Why it remain visible when you comes back to the activity.
So Try to open keyboard on Button Click this way..
EditText editText = (EditText) findViewById(R.id.myEdit);
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// only will trigger it if no physical keyboard is open
mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
And if there are any windowSoftInputMode
in Manifest,Remove them cause will not need them for above method.
尝试在edittext的对象上使用setfocus方法
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.