Android全面屏刘海屏适配,状态栏颜色修改,状态栏文字颜色修改

1.全屏显示

//状态栏颜色

implementation 'com.githang:status-bar-compat:0.7'

override fun onCreate(savedInstanceState:Bundle?) {

super.onCreate(savedInstanceState)

if (fullScreen()) {

// 延伸显示区域到刘海

        val lp =this.window.attributes

        if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.P) {

lp.layoutInDisplayCutoutMode =

WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES

            this.window.attributes = lp

}

}else {

StatusBarCompat.setStatusBarColor(this,statusBarColor())

}

}

2.设置状态栏颜色

/**

* 把状态栏设成其他颜色

*/

open fun setStatusBarColor(color:Int) {

if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.LOLLIPOP) {

val decorView =window.decorView

        decorView.setOnApplyWindowInsetsListener {v:View,insets:WindowInsets? ->

val defaultInsets =v.onApplyWindowInsets(insets)

defaultInsets.replaceSystemWindowInsets(

defaultInsets.systemWindowInsetLeft,

0,

defaultInsets.systemWindowInsetRight,

defaultInsets.systemWindowInsetBottom

            )

}

ViewCompat.requestApplyInsets(decorView)

window.statusBarColor =ContextCompat.getColor(this,color)

}

}

3修改状态栏字体颜色

/**

* 设置状态栏文字色值为深色调

*

* @param useDart  是否使用深色调

* @param activity

*/

public static void setStatusTextColor(boolean useDart,Activity activity) {

if (isFlyme()) {

processFlyMe(useDart,activity);

}else if (isMIUI()) {

processMIUI(useDart,activity);

}else if (Rom.isOppo()) {

setOppoLightStatusBarIcon(true,activity);

}else {

if (useDart) {

if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.M) {

activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);

}

}else {

activity.getWindow().getDecorView().setSystemUiVisibility(

View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

}

activity.getWindow().getDecorView().findViewById(android.R.id.content).setPadding(0,0,0,BarModeColorUtils.navigationHeight);

}

}

/**

* 接口传入值ture时状态栏图标为黑色,接口转入值为false状态栏图标为白色

* oppo 视频状态栏

* @param lightMode

* @param activity

*/

private static void setOppoLightStatusBarIcon(boolean lightMode,Activity activity) {

int SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT =0x00000010;

if (Build.VERSION.SDK_INT ==Build.VERSION_CODES.LOLLIPOP) {

Window window =activity.getWindow();

window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

window.getDecorView().setSystemUiVisibility(SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT);

}else {

Window window =activity.getWindow();

window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

int vis = window.getDecorView().getSystemUiVisibility();

if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.M) {

if (lightMode) {

vis |=View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;

}else {

vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;

}

}else if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.LOLLIPOP) {

if (lightMode) {

vis |= SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT;

}else {

vis &= ~SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT;

}

}

window.getDecorView().setSystemUiVisibility(vis);

}

}

转载请标明出处!!!

你可能感兴趣的:(Android全面屏刘海屏适配,状态栏颜色修改,状态栏文字颜色修改)