有效获取状态栏(StatusBar)高度

碰到了需要获取状态栏高度的问题。

就像android后期版本,无法直接退出一样。找了一些方法来获取状态栏高度,结果都是为0.

还好,牛人是很多的,当时,找到一段代码,能够有效的获取状态栏的高度。特此记录,备忘,以及供大家参考。

?
Class<?> c = null ;
Object obj = null ;
Field field = null ;
int x = 0 , sbar = 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());
     sbar = getResources().getDimensionPixelSize(x);
} catch (Exception e1) {
     loge( "get status bar height fail" );
     e1.printStackTrace();

 同时,也希望看小说的朋友们,可以使用下兄弟做的小应用,自我感觉阅读翻页效果还凑合(自己制作的哈)。

萧潜 飘邈之旅 :http://apk.gfan.com/Product/App185125.html

慕容湮儿 倾世皇妃 :http://apk.gfan.com/Product/App188511.html

效果图:

有效获取状态栏(StatusBar)高度 有效获取状态栏(StatusBar)高度 有效获取状态栏(StatusBar)高度

你可能感兴趣的:(status)