public void applyDark(DarkReceiver object) {}
//安卓P会监听应用主题变化,亮色主题,设置字体和图标黑色, 黑色主题设置字体和图标等白色,通过onDarkChanged回调给ui。 //darkIntensity 为0f 则设置白色 ,为1f则设置黑色interface DarkReceiver {
void onDarkChanged(Rect area, float darkIntensity, int tint); } public void onDarkChanged(Rect area, float darkIntensity, int tint) { mTextView.setTextColor(DarkIconDispatcher.getTint(area, this, tint)); } int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground); float intensity = colorForeground == Color.WHITE ? 0f : 1f; Rect tintArea = new Rect(0, 0, 0, 0); darkIntensity 为0f 则设置白色 ,为1f则设置黑色 //应用中调用切换systemui 字体图标颜色,可以通过如下方式切换/**
* Android 6.0 以上设置状态栏颜色 */int flag = 0;
protected void setStatusBar() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {// 设置状态栏底色颜色
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); getWindow().setStatusBarColor(getColor(R.color.text_color));// 如果亮色,设置状态栏文字为黑色
if (flag == 0) { flag = 1; getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); } else { flag = 0; getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } }}