获取状态栏、标题栏高度

来源:互联网 发布:用手机淘宝注册账号 编辑:程序博客网 时间:2024/05/19 21:41

获取状态栏高度

getActionBar().getHeight();

获取标题栏高度

    /**     * 获取状态栏高度     *     * @return     */    public static int getStatusBarHeight(Context context) {        Class<?> c = null;        Object obj = null;        java.lang.reflect.Field field = null;        int x = 0;        int statusBarHeight = 0;        try {            c = Class.forName("com.android.internal.R$dimen");            obj = c.newInstance();            field = c.getField("status_bar_height");            x = Integer.parseInt(field.get(obj).toString());            statusBarHeight = context.getResources().getDimensionPixelSize(x);            Log.e("标题栏高度", String.valueOf(statusBarHeight));            return statusBarHeight;        } catch (Exception e) {            e.printStackTrace();        }        return statusBarHeight;    }
原创粉丝点击