读书人

2013.03.19(五)android 获取状

发布时间: 2013-03-21 10:08:17 作者: rapoo

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

读书人网 >Android

热点推荐