tnblog
首页
视频
资源
登录

Android 获取导航栏的高度

6554人阅读 2020/4/8 9:28 总访问:115076 评论:0 收藏:0 手机
分类: Abp

获取Android手机屏幕的高度

  1. /**
  2.  * 获取状态栏高度 
  3.  * 
  4.  * @param context 上下文
  5.  * @return 高度
  6.  */public static int getStatusBarHeight(Context context) {
  7.     int result = 0;
  8.     int resId = context.getResources().getIdentifier("status_bar_height""dimen""android");
  9.     if (resId > 0) {
  10.         result = context.getResources().getDimensionPixelSize(resId);
  11.     }
  12.     return result;}
  1. /**
  2.  * 获取导航栏高度
  3.  *
  4.  * @param context 上下文
  5.  * @return 高度
  6.  */public static int getNavigationHeight(Context context) {
  7.     int resourceId = 0;
  8.     int rid = context.getResources().getIdentifier("config_showNavigationBar""bool""android");
  9.     if (rid != 0) {
  10.         resourceId = context.getResources().getIdentifier("navigation_bar_height""dimen""android");
  11.         return context.getResources().getDimensionPixelSize(resourceId);
  12.     } else{
  13.         return 0;
  14.     }}


评价
希望你懂得很多之后,依旧热爱生活
排名
31
文章
25
粉丝
11
评论
6
MUI 页面传值
是伍尚金哇 : 翻了半天不到底
MUI 页面传值
剑轩 : 可以,在写文章的时候,有需要写代码的地方,可以选择编辑器上的...
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术
就像那句狠话:有一天,我一定会后悔的。