Android判断底部导航是否显示的方法

众所周知,Android碎片化严重的问题,对于底部导航的隐藏和显示出了N多个版本的问题。在开发的时候,又遇到了底部导航的问题,所以在此记录一下 处理方案。手头测试机数量有限,该方法对于小米,vivio,华为均适用。 直接看代码吧 。

 /**
     * @return 是否显示底部导航
     */
    public static boolean isShowNav(Activity activity) {
        boolean flag = false;
       View content = activity.getWindow().getDecorView().findViewById(android.R.id.content);
       if ( null  != content) {
                WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
                Display display = wm.getDefaultDisplay();
                Point point = new Point();
                display.getRealSize(point);
                if (!isLandscape()) {
                    int bottom = content.getBottom();// 页面的底部
                    if (bottom != point.y) {
                        flag = true;
                 }
       } else {
                    int right = content.getRight();
                    if (right != point.y) {
                        flag = true;
                    }
                }
            }
      }
        return flag;
    }

其中,isLandscape方法,是用来判断当前页面是横屏还是竖屏 。

  /**
   * Return whether screen is landscape.
   *
   * @return {@code true}: yes<br>{@code false}: no
   */
  public static boolean isLandscape() {
      return Utils.getApp().getResources().getConfiguration().orientation
              == Configuration.ORIENTATION_LANDSCAPE;
  }

需要的同学 可以测试一下 。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值