尝试做下面提到的事情可能会对您的示例有所帮助。如果您仍然面临问题,请告诉我。如果它可以解决您的问题,请提供答案。
AndroidManifest.xml
<activity
....
android:theme="@style/TranslucentStatusBarTheme">
</activity>
values-v23\styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TranslucentStatusBarTheme" parent="AppTheme">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowLightStatusBar">true</item>
</style>
</resources>
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);
}