尝试做下面提到的事情可能会帮助你的例子。如果你仍然面临问题,请跟我说。如果它能解决您的问题,那么请提供答案。

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);

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐