【问题标题】:How can I make the navigation bar visible only when the soft keyboard is open?如何使导航栏仅在软键盘打开时可见?
【发布时间】:2021-05-23 17:29:23
【问题描述】:

我有一个应用程序,大部分时间都应该全屏显示。但是,我希望用户在使用键盘时能够轻松返回。如何使导航栏仅在键盘打开时可见?当键盘关闭时,导航栏应该会再次消失。

【问题讨论】:

    标签: java android android-studio navigationbar android-navigation-bar


    【解决方案1】:

    我将此库添加到我的项目中。所以我可以在键盘打开时输入要做什么:

    implementation 'com.github.ravindu1024:android-keyboardlistener:1.0.0'
    

    然后我创建了两个值,一个显示一个隐藏:

    private int showSystemBars() {
        return SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN  |
                SYSTEM_UI_FLAG_LAYOUT_STABLE;
    }
    
    private int hideSystemBars() {
        return SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    }
    

    然后我使用了我添加的库:

    KeyboardUtils.addKeyboardToggleListener(this, isVisible -> {
            if (isVisible) {
                Toast.makeText(context, "Visible", Toast.LENGTH_SHORT).show();
                getWindow().getDecorView().setSystemUiVisibility(showSystemBars());
            }else {
                Toast.makeText(context, "Invisible", Toast.LENGTH_SHORT).show();
                getWindow().getDecorView().setSystemUiVisibility(hideSystemBars());
            }
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-17
      • 1970-01-01
      • 2022-12-02
      • 2016-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多