美文网首页高级UI
Android沉浸式状态栏,支持状态栏渐变色,纯色, 全屏,亮光

Android沉浸式状态栏,支持状态栏渐变色,纯色, 全屏,亮光

作者: 夜猫少年 | 来源:发表于2020-04-28 13:58 被阅读0次

    StatusBarUtil

    适用于Android 4.4-10.0型号的状态栏,具有改进的色彩,渐变和沉浸式体验

    Sample

    Download Apk

    Demo

    Demo Link

    机型演示

    Android-9.0 Android-4.4
    Android-9.0-min.gif Android-4.4-min.gif

    Gradle引用

    repositories {
        ...
        maven { url 'https://www.jitpack.io' }
    }
    
    dependencies {
        implementation 'com.github.Ye-Miao:StatusBarUtil:1.7.5'
    }
    

    使用方法

    设置纯色状态栏

    in your layout XML

    <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/blue"/>
    

    in your activity

    StatusBarUtil.setColor(this, mColor);
    

    设置渐变色状态栏

    in your layout XML

    <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/blue"/>
    

    in your activity

    StatusBarUtil.setGradientColor(this, mToolbar);
    

    设置透明状态栏

    in your activity

    StatusBarUtil.setTransparentForWindow(this);
    

    设置亮色状态栏(适用于Android6.0及以上)

    in your activity

    StatusBarUtil.setLightMode(this);
    

    设置暗色状态栏(适用于Android6.0及以上)

    in your activity

    StatusBarUtil.setDarkMode(this);
    

    增加View的paddingTop,增加的值是状态栏高度(具体用途可以在demo中引用)

    可以将Toolbar高度延伸到状态栏以实现纯色状态栏

    in your layout XML

    <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/blue"/>
    

    in your activity

    StatusBarUtil.setPaddingTop(this, mToolbar);
    

    可以将Toolbar高度延伸到状态栏以实现渐变色状态栏

    in your layout XML

    <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/gradient_color"
    

    in your activity

    StatusBarUtil.setPaddingTop(this, mToolbar);
    

    相关文章

      网友评论

        本文标题:Android沉浸式状态栏,支持状态栏渐变色,纯色, 全屏,亮光

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