美文网首页Note_Android
解决华为等型号虚拟按键影响布局问题

解决华为等型号虚拟按键影响布局问题

作者: Qin0821 | 来源:发表于2017-07-14 12:05 被阅读0次

    给布局文件根控件设置padding即可,以下是Kotlin代码:

        setContentView(R.layout.activity_home)
        homeLayout!!.setPadding(0, BaseActivity.getStatusHeight(context), 0, BaseActivity.getBottomStatusHeight(context))
    
    

    BaseActivity尚未转换为Kotlin:

        /**
         * 获得状态栏的高度
         */
        public static int getStatusHeight(Context context) {
    
            int statusHeight = -1;
            try {
                Class<?> clazz = Class.forName("com.android.internal.R$dimen");
                Object object = clazz.newInstance();
                int height = Integer.parseInt(clazz.getField("status_bar_height")
                        .get(object).toString());
                statusHeight = context.getResources().getDimensionPixelSize(height);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return statusHeight;
        }
    
        /**
         * 获取 虚拟按键的高度
         */
        public static int getBottomStatusHeight(Context context) {
            int totalHeight = getDpi(context);
    
            int contentHeight = getScreenHeight(context);
    
            return totalHeight - contentHeight;
        }
    
    

    相关文章

      网友评论

        本文标题:解决华为等型号虚拟按键影响布局问题

        本文链接:https://www.haomeiwen.com/subject/zbvnhxtx.html