Window
public abstract class Window
extends Object
java.lang.Object | |
↳ | android.view.Window |
Abstract base class for a top-level window look and behavior policy. An instance of this class should be used as the top-level view added to the window manager. It provides standard UI policies such as a background, title area, default key processing, etc.
The only existing implementation of this abstract class is android.view.PhoneWindow, which you should instantiate when needing a Window.
setStatusBarColor 设置状态栏颜色
void setStatusBarColor (int color)
Sets the color of the status bar to color
. For this to take effect, the window must be drawing the system bar backgrounds with FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
andFLAG_TRANSLUCENT_STATUS
must not be set. If color
is not opaque, consider setting SYSTEM_UI_FLAG_LAYOUT_STABLE
and SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
.
(必须先设置FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,而不能设置 FLAG_TRANSLUCENT_STATUS
)
The transitionName for the view background will be "android:status:background".
Parameters | |
---|---|
color | int |
setNavigationBarColor
void setNavigationBarColor (int color)
Sets the color of the navigation bar to . For this to take effect, the window must be drawing the system bar backgrounds with FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
andFLAG_TRANSLUCENT_NAVIGATION
must not be set. If is not opaque, consider setting SYSTEM_UI_FLAG_LAYOUT_STABLE
and SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
.
(必须先设置FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,而不能设置 FLAG_TRANSLUCENT_NAVIGATION)
The transitionName for the view background will be "android:navigation:background".
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);//设置状态栏透明
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); //设置导航栏透明
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //window.setStatusBarColor(0xffff0000); //设置状态栏颜色 window.setNavigationBarColor(0xFF607D8B); //设置导航栏颜色
WindowManager.LayoutParams
public static class WindowManager.LayoutParams
extends ViewGroup.LayoutParams
implements Parcelable
java.lang.Object | ||
↳ | android.view.ViewGroup.LayoutParams | |
↳ | android.view.WindowManager.LayoutParams |
FLAG_TRANSLUCENT_STATUS 设置状态栏透明
int FLAG_TRANSLUCENT_STATUS
Window flag: request a translucent status bar with minimal system-provided background protection.
This flag can be controlled in your theme through the windowTranslucentStatus
attribute; this attribute is automatically set for you in the standard translucent decor themes such as Theme_Holo_NoActionBar_TranslucentDecor
, Theme_Holo_Light_NoActionBar_TranslucentDecor
,Theme_DeviceDefault_NoActionBar_TranslucentDecor
, and Theme_DeviceDefault_Light_NoActionBar_TranslucentDecor
.
When this flag is enabled for a window, it automatically sets the system UI visibility flags SYSTEM_UI_FLAG_LAYOUT_STABLE
and SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
.
Constant Value: 67108864 (0x04000000)
FLAG_TRANSLUCENT_NAVIGATION 设置导航栏透明
int FLAG_TRANSLUCENT_NAVIGATION
Window flag: request a translucent navigation bar with minimal system-provided background protection.
This flag can be controlled in your theme through the windowTranslucentNavigation
attribute; this attribute is automatically set for you in the standard translucent decor themes such as Theme_Holo_NoActionBar_TranslucentDecor
, Theme_Holo_Light_NoActionBar_TranslucentDecor
,Theme_DeviceDefault_NoActionBar_TranslucentDecor
, and Theme_DeviceDefault_Light_NoActionBar_TranslucentDecor
.
When this flag is enabled for a window, it automatically sets the system UI visibility flags SYSTEM_UI_FLAG_LAYOUT_STABLE
and SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
.
Constant Value: 134217728 (0x08000000)
QtMyActivity.java
public class QtMyActivity extends org.qtproject.qt5.android.bindings.QtActivity { // @SuppressLint("InlinedApi") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS // | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); // getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); // getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); // getWindow().setStatusBarColor(Color.TRANSPARENT); // getWindow().getDecorView().setFitsSystemWindows(true); // getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); // window.setStatusBarColor(0xffff0000); window.setNavigationBarColor(0xFF607D8B); } }