本文實例講述了Android編程獲取通知欄高度的方法。分享給大家供大家參考,具體如下:
這里通過反射機制獲取通知欄高度
通知欄高度寫在dimen文件中:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
public static int getStatusBarHeight(Context context){ Class<?> c = null ; Object obj = null ; Field field = null ; int x = 0 , statusBarHeight = 0 ; try { c = Class.forName( "com.android.internal.R$dimen" ); obj = c.newInstance(); field = c.getField( "status_bar_height" ); x = Integer.parseInt(field.get(obj).toString()); statusBarHeight = context.getResources().getDimensionPixelSize(x); } catch (Exception e1) { e1.printStackTrace(); } return statusBarHeight; } |
希望本文所述對大家Android程序設計有所幫助。