zoukankan      html  css  js  c++  java
  • Android:沉浸式状态栏(二)集成

    1. 在Activity的onCreate()方法中添加代码
    //设置状态栏透明
    StatusBarUtil.setTranslucentStatus(this);
    //设置透明状态栏的paddingTop为false
    setRootViewFitsSystemWindows(this,false);
    
    

    在使用中经常会遇到图标和标题栏重叠的情况,可以使用StatusBarHeightView这个控件填充状态栏上方的位置

    package com.onepilltest.util;
    
    import android.content.Context;
    import android.content.res.TypedArray;
    import android.os.Build;
    import android.support.annotation.Nullable;
    import android.util.AttributeSet;
    import android.widget.LinearLayout;
    
    import com.onepilltest.R;
    
    public class StatusBarHeightView extends LinearLayout {
        private int statusBarHeight;
        private int type;
    
        public StatusBarHeightView(Context context, @Nullable AttributeSet attrs) {
            super(context, attrs);
            init(attrs);
        }
    
        public StatusBarHeightView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
            init(attrs);
        }
    
        public StatusBarHeightView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
            super(context, attrs, defStyleAttr);
            init(attrs);
    
    
        }
    
        private void init(@Nullable AttributeSet attrs) {
    
            int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                if(resourceId>0) {
                    statusBarHeight = getResources().getDimensionPixelSize(resourceId);
                }
            }else{
                //低版本 直接设置0
                statusBarHeight = 0;
            }
            if (attrs != null) {
                TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.StatusBarHeightView);
                type = typedArray.getInt(R.styleable.StatusBarHeightView_use_type, 0);
                typedArray.recycle();
            }
            if (type == 1) {
                setPadding(getPaddingLeft(), statusBarHeight, getPaddingRight(), getPaddingBottom());
            }
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            if (type == 0) {
                setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
                        statusBarHeight);
            } else {
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            }
        }
    }
    
    
  • 相关阅读:
    Bootstrap入门(二十五)JS插件2:过渡效果
    Bootstrap入门(二十四)data属性
    Bootstrap入门(二十三)JS插件1:模态框
    Bootstrap入门(二十二)组件16:列表组
    Bootstrap入门(二十一)组件15:警告框
    Bootstrap入门(二十)组件14:警告框
    Bootstrap入门(十九)组件13:页头与缩略图
    git 上传本地代码到github 服务器
    Dropzone.js实现文件拖拽上传
    将复杂form表单序列化serialize-object.js
  • 原文地址:https://www.cnblogs.com/charlottepl/p/12893223.html
Copyright © 2011-2022 走看看