java代码设置状态栏颜色_java - 如何将状态栏设置为透明但导航栏保持黑色? - SO中文参考 - www.soinside.com...
尝试做下面提到的事情可能会帮助你的例子。如果你仍然面临问题,请跟我说。如果它能解决您的问题,那么请提供答案。AndroidManifest.xml....android:theme="@style/TranslucentStatusBarTheme">values-v23\styles.xml@android:color/transparenttrueActivity.javaprivate
尝试做下面提到的事情可能会帮助你的例子。如果你仍然面临问题,请跟我说。如果它能解决您的问题,那么请提供答案。
AndroidManifest.xml
....
android:theme="@style/TranslucentStatusBarTheme">
values-v23\styles.xml
@android:color/transparent
true
Activity.java
private static void setWindowFlag(Activity activity, boolean on) {
Window win = activity.getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
if (on) {
winParams.flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
} else {
winParams.flags &= ~WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
}
win.setAttributes(winParams);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// Check if the version of Android is Marshmallow or higher
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int newUiOptions = getWindow().getDecorView().getSystemUiVisibility();
newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
getWindow().getDecorView().setSystemUiVisibility(newUiOptions
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
// Check if the version of Android is Lollipop or higher
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
setWindowFlag(this, false);
getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.colorTranslucent));
}
super.onCreate(savedInstanceState);
}
更多推荐
所有评论(0)