简体   繁体   English

Android软键盘:隐藏然后立即显示

[英]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. 假设我有一个显示片段A的活动。从片段A中,我单击一个按钮以切换到片段B。在片段A上,我在onPause()方法中隐藏了软键盘。 On Fragment B, i show the soft keyboard in onResume() method. 在片段B上,我以onResume()方法显示软键盘。

Now when i click the button, fragment B is shown but the keyboard is not shown, which is not good. 现在,当我单击按钮时,显示了片段B,但未显示键盘,这不好。 If fragment A doesn't use keyboard (remove the hide-soft-keyboard code in onPause()), then it works fine. 如果片段A不使用键盘(删除onPause()中的hide-soft-keyboard代码),则可以正常工作。

I set the breakpoint, and definitely fragment A's onPause is called before fragment B's onResume(). 我设置了断点,并且肯定在片段B的onResume()之前调用了片段A的onPause。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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