【问题标题】:How to hide Bottom Navigation menu when soft keyboard appears? [closed]出现软键盘时如何隐藏底部导航菜单? [关闭]
【发布时间】:2019-08-31 10:19:45
【问题描述】:

我知道将 adjustPan 设置为隐藏底部导航菜单,但效果会向上推 RecyclerView & Toolbar。我试过设置adjustResize。它工作正常,但底部导航仍然显示。

我想隐藏底部导航菜单,但保留 RecyclerView 和工具栏的 adjustResize 效果。

【问题讨论】:

标签: android bottomnavigationview


【解决方案1】:

在父视图上使用 ViewTreeObserver

parentView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
        Rect r = new Rect();
        parentView.getWindowVisibleDisplayFrame(r);
        int screenHeight = container.getRootView().getHeight();
        // r.bottom is the position above soft keypad or device button.
        // if keypad is shown, the r.bottom is smaller than that before.
        int keypadHeight = screenHeight - r.bottom;
        // 0.15 ratio is perhaps enough to determine keypad height.
        if (keypadHeight > screenHeight * 0.15) {
            // keyboard is opened
            bottomLayout.setVisibility(View.GONE);
        } else {
            // keyboard is closed
            bottomLayout.post(() -> bottomLayout.setVisibility(View.VISIBLE));
        }
    });

【讨论】:

  • 大力支持!..谢谢
猜你喜欢
  • 2013-12-09
  • 1970-01-01
  • 2017-08-24
  • 2012-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多