开发者

Opening softkeyboard again when entering activity from back button

开发者 https://www.devze.com 2023-03-04 19:15 出处:网络
I use android:windowSoftInputMode=\"stateVisible|adjustPan\" in my manifest file to open the softkeyboard when the main activity is launched.

I use android:windowSoftInputMode="stateVisible|adjustPan" in my manifest file to open the softkeyboard when the main activity is launched.

开发者_如何学C

This works great, apart from when i come back to the main activity from another using the back button; The softkeyboard does not reappear.

How do i make the softkeyboard appear when coming back to the main activity?

Thanks for any help in advance.


On back button it just remove the current activity from the stack and show the previous activity that is why softkeyboard is not getting opened . you can override the onKeyDown() method and on back button you can call your activity again.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {

        // start your activity again here
        Log.d(this.getClass().getName(), "back button pressed");
    }
    return super.onKeyDown(keyCode, event);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号