简体   繁体   中英

Android soft keyboard : hide then show immediately

Say i have an activity that shows fragment A. From fragment A i click a button to switch to fragment B. On Fragment A, i hide the soft keyboard in onPause() method. On Fragment B, i show the soft keyboard in onResume() method.

Now when i click the button, fragment B is shown but the keyboard is not shown, which is not good. If fragment A doesn't use keyboard (remove the hide-soft-keyboard code in onPause()), then it works fine.

I set the breakpoint, and definitely fragment A's onPause is called before fragment B's onResume(). So in theory i think the keyboard should still be shown no matter what.

Any idea ?

You could delay the shown of the keyboard a little. something like:

Handler handler = new Handler();
handler.postDelayed(new Runnable(){
    @Override
    public void run(){
        //show the keybpoard
    }

}, 500);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM