2013.03.19(5)———android 获取状态栏的高度

2013.03.19(5)———android 获取状态栏的高度

参考: http://blog.csdn.net/dany1202/article/details/6571010

我需要获取状态栏的高度 来精确的算出可用区域的高度 ,上网找了半天 都不行 最后 ok了 方法如下 :

public static int getScreenHeight(Context context){
        Class c;
        int y = 0;
        try {
            c = Class.forName("com.android.internal.R$dimen");
            Object obj = c.newInstance();
            Field field = c.getField("status_bar_height");
            int x = Integer.parseInt(field.get(obj).toString());
            y = context.getResources().getDimensionPixelSize(x);
            System.out.println(x+"======="+y);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return getAllHeight(context) - y;
    }

猜你喜欢

转载自trylovecatch.iteye.com/blog/1831894