设置状态栏、导航栏颜色

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        设置状态栏颜色

added in  API level 21
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
colorint

 

setNavigationBarColor

added in  API level 21
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 设置状态栏透明

added in  API level 19
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_TranslucentDecorTheme_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  设置导航栏透明

added in  API level 19
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_TranslucentDecorTheme_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);

    }
}

 

转载于:https://www.cnblogs.com/qiuly/p/7205046.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值