• 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;
        }
  • 相关阅读:
    Protobuf通信协议
    python发送消息到activeMQ后java接收到BinaryMessage的坑
    golang time.Duration() 问题
    golang操作redis
    golang之网络编程
    golang之反射
    golang之goroutine和channel
    golang之单元测试
    golang之文件操作
    XmlHelper 工具类
  • 原文地址:https://www.cnblogs.com/caoxinyu/p/6647800.html
Copyright © 2020-2023  润新知