zoukankan      html  css  js  c++  java
  • Android获取状态栏的高度:

    方法一:

        //获取手机状态栏高度
        public static int getStatusBarHeight(Context context){
            Class<?> c = null;
            Object obj = null;
            Field field = null;
            int x = 0, 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);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            return statusBarHeight;
        }

    方法二:(在onResume里面获取,在onCreate 里面可能获取不到)

    Rect rect = new Rect();
                        getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
                        IMenu.MENU_FOOT_HEI = rect.top;

    方法三:

        /**
         * 获取状态栏高度
         *
         * @param context
         * @return
         */
        public static int getStatusBarHeight(Context context) {
            int result = 0;
            int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
            if (resourceId > 0) {
                result = context.getResources().getDimensionPixelSize(resourceId);
            }
            return result;
        }
  • 相关阅读:
    sort
    usaco-3.1-humble-pass
    usaco-3.1-inflate-pass
    usaco-3.1-agrinet-pass
    usaco-2.4-fracdec-pass
    usaco-2.4-comhome-pass
    usaco-2.4-cowtour-pass
    usaco-2.4-maze1-pass
    usaco-2.4-ttwo-pass
    usaco-2.3-concom-pass
  • 原文地址:https://www.cnblogs.com/caoxinyu/p/10568702.html
Copyright © 2011-2022 走看看