Android一些设备都有上下两条bar,我们可以获取这些bar的信息。下面放上获取高度的代码。代码注释和其他方法有空再放。

原文地址请保留http://www.cnblogs.com/rossoneri/p/4142962.html

获取顶部status bar 高度

private int getStatusBarHeight() {
    Resources resources = mActivity.getResources();
    int resourceId = resources.getIdentifier("status_bar_height", "dimen","android");
    int height = resources.getDimensionPixelSize(resourceId);
    Log.v("dbw", "Status height:" + height);
    return height;
}

获取底部 navigation bar 高度

private int getNavigationBarHeight() {
    Resources resources = mActivity.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height","dimen", "android");
    int height = resources.getDimensionPixelSize(resourceId);
    Log.v("dbw", "Navi height:" + height);
    return height;
}

 

相关文章:

  • 2021-12-04
  • 2017-12-20
  • 2021-10-21
  • 2021-07-31
  • 2021-11-20
  • 2022-12-23
  • 2021-07-10
猜你喜欢
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2021-11-24
  • 2022-12-23
相关资源
相似解决方案