1.全屏顯示
//狀態(tài)欄顏色
implementation 'com.githang:status-bar-compat:0.7'
override fun onCreate(savedInstanceState:Bundle?) {
super.onCreate(savedInstanceState)
if (fullScreen()) {
// 延伸顯示區(qū)域到劉海
? ? ? ? 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.設置狀態(tài)欄顏色
/**
* 把狀態(tài)欄設成其他顏色
*/
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修改狀態(tài)欄字體顏色
/**
* 設置狀態(tài)欄文字色值為深色調(diào)
*
* @param useDart? 是否使用深色調(diào)
* @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時狀態(tài)欄圖標為黑色,接口轉入值為false狀態(tài)欄圖標為白色
* oppo 視頻狀態(tài)欄
* @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);
}
}