如何使导航栏仅在软键盘打开时可见?

How can I make the navigation bar visible only when the soft keyboard is open?

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

我将这个库添加到我的项目中。所以我能够输入键盘打开时要执行的操作:

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());
        }
    });