Android編程獲取通知欄高度的方法
更新時間:2016年01月11日 09:30:10 作者:java2009cgh
這篇文章主要介紹了Android編程獲取通知欄高度的方法,涉及Android針對通知欄屬性相關操作技巧,需要的朋友可以參考下
本文實例講述了Android編程獲取通知欄高度的方法。分享給大家供大家參考,具體如下:
這里通過反射機制獲取通知欄高度
通知欄高度寫在dimen文件中:
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程序設計有所幫助。
您可能感興趣的文章:
相關文章
Android性能優(yōu)化之RecyclerView分頁加載組件功能詳解
這篇文章主要為大家介紹了Android性能優(yōu)化之RecyclerView分頁加載組件功能詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-09-09
android?studio組件通信:Intend啟動Activity接收返回結果
這篇文章主要介紹了android?studio組件通信:Intend啟動Activity接收返回結果,設計一個主Activity和一個子Activity(Sub-Activity),使用主Activity上的按鈕啟動子Activity,并將子Activity的一些信息返回給主Activity,并顯示在主Activity上,需要的朋友可以參考一下2021-12-12

