您的位置:首页 > 移动开发 > Android开发

Android分别获取导航栏、状态栏高度

2018-03-06 12:01 579 查看
名词解析:



方法
/**
//透明状态栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//透明导航栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

* 获取状态栏高度
* @param context
* @return
*/
public static int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen",
"android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}

/**
* 获取导航栏高度
* @param context
* @return
*/
public static int getDaoHangHeight(Context context) {
int result = 0;
int resourceId=0;
int rid = context.getResources().getIdentifier("config_showNavigationBar", "bool", "android");
if (rid!=0){
resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
CMLog.show("高度:"+resourceId);
CMLog.show("高度:"+context.getResources().getDimensionPixelSize(resourceId) +"");
return context.getResources().getDimensionPixelSize(resourceId);
}else
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐