安卓得到狀態欄的高度

 public static int getStatusBarHeight(Resources resources) 
    { 
        Class<?> c = null; 
        Object obj = null; java

       java.lang.reflect.Field field = null; 
        int x = 0; 
        int statusBarHeight = 0; 
        try android


            c = Class.forName("com.android.internal.R$dimen"); 
            obj = c.newInstance(); 
            field =c.getField("status_bar_height"); get

           x = Integer.parseInt(field.get(obj).toString()); 
            statusBarHeight = resources.getDimensionPixelSize(x);  
      }catch (Exception e){ 
            e.printStackTrace(); 
        } 
        return statusBarHeight; io

}im

相關文章
相關標籤/搜索