获取状态栏高度

Android中获取状态栏高度的两种方法:

     public static int getStatusHeight(Context context)
     {

        int statusHeight = 0;
        try
        {
            Class<?> clazz = Class.forName("com.android.internal.R$dimen");
            Object object = clazz.newInstance();
            int resourceId = Integer.parseInt(clazz.getField("status_bar_height").get(object).toString());
            statusHeight = context.getResources().getDimensionPixelSize(resourceId);
        } 
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return statusHeight;
     }
     
     public static int getStatusHeight2(Context context) 
     {
         int statusHeight = 0;
         int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
         if (resourceId > 0) 
         {
             statusHeight = context.getResources().getDimensionPixelSize(resourceId);
         }
         return statusHeight;
    }
原文地址:https://www.cnblogs.com/rainboy2010/p/5022003.html