天天看點

android沉浸式狀态欄簡單實作

android沉浸式狀态欄簡單實作,一行代碼

在Base類中加入onCreate()方法中加入:

BaseActivity.class

//設定式沉浸式狀态的顔色
StatusBarCompat.setStatusBarColor(this, getResources().getColor(R.color.status_bar), false);      

在color中加入方法中加入:

color.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
       
<color name="status_bar">#26c1ff</color>
<!--狀态欄-->      
</resources>      

在src檔案下的build.fradle加入:

compile 'com.githang:status-bar-compat:latest.integration'

盡量直接加入,然後點選左上角sync now 

在Project Structure--app--Deendencies中搜尋,可能會搜尋不到


      
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'


android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.example"
        minSdkVersion 22
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //retrofit
    //rxjava
    //rxandroid
    //配合Rxjava 使用
    //轉換器 将結果通過gson将json串轉換為model
    //GSON庫
    //recyclerview
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'io.reactivex.rxjava2:rxjava:2.1.1'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'
    compile 'com.google.code.gson:gson:2.8.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.jakewharton:butterknife:8.8.0'
    compile 'com.android.support:design:26.0.0-alpha1'
    testCompile 'junit:junit:4.12'
    apt 'com.jakewharton:butterknife-compiler:8.8.0'
    //沉浸式狀态欄
    compile 'com.githang:status-bar-compat:latest.integration'
}