简体   繁体   English

软键盘不可见后隐藏在屏幕的主页和后退按钮上

[英]Hiding on screen home and back buttons after soft keyboard goes unvisible

I can hide on screen home and back buttons like this: 我可以在屏幕上隐藏主页和后退按钮,如下所示:

@Override protected void onCreate(Bundle savedInstanceState)
    {
        this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        this.getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);)
    }

and same as onResume. 和onResume一样。 But when my app opens the soft keyboard the buttons comes again and doesn't disappear after keyboard closes. 但是,当我的应用程序打开软键盘时,按钮会再次出现,并且在键盘关闭后不会消失。 I want home and back buttons to be invisible after soft keyboard is hidden. 我希望隐藏软键盘后不显示主页和后退按钮。 Any help would be appreciated. 任何帮助,将不胜感激。

May be you can use a workaround solution for that, you can listen to the soft keyboard dismissing and then when dismissed try to set these flags again. 可能是您可以使用一种解决方法,可以听见软键盘的关闭,然后在关闭时尝试再次设置这些标志。

To listen to the keyboard dismissing( got it from here )and then set the flags again, so the complete solution would be : 要收听键盘关闭声( 从此处获得 ),然后再次设置标志,因此完整的解决方案是:

final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
        if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                this.getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);)
        }
     }
});

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

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