首页 > 其他 > 详细

获取状态栏高度

时间:2015-12-05 19:18:54      阅读:155      评论:0      收藏:0      [点我收藏+]

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;
    }

 

获取状态栏高度

原文:http://www.cnblogs.com/rainboy2010/p/5022003.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!