隐藏状态栏时,整体布局不会往上挪的办法

Launcher开发的时候有个需求是长按图标时,要隐藏状态栏弹出卸载框。但是发现隐藏状态栏的时候workspace会整体往上挪,要想隐藏状态栏时布局不变,需要先在主题属性里加两个属性就好了:


    <style name="Theme" parent="@android:style/Theme.Holo.Wallpaper.NoTitleBar">
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
    </style>

代码里隐藏和显示状态栏的代码:

    public void showStatusBar() {
//        if (mLauncherView != null) {
//            mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.VISIBLE);
//        }
    	WindowManager.LayoutParams attrs = getWindow().getAttributes();        
    	attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;        
    	getWindow().setAttributes(attrs);
    }

    public void hideStatusBar() {
//        if (mLauncherView != null) {
//            mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.INVISIBLE);
//        }
    	WindowManager.LayoutParams attrs = getWindow().getAttributes();        
    	attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;        
    	getWindow().setAttributes(attrs);
    }

上面的函数在 android7.1上已经无效了,布局还是会上移。7.1后使用下面可以使用下面的函数:

public void showStatusBar() {
    int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;  
        uiFlags |= 0x00001000;  
        getWindow().getDecorView().setSystemUiVisibility(uiFlags);  
    Log.d("Launcher_status_bar", "Launcher showStatusBar()");
}

public void hideStatusBar() {
int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE  
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN  
| View.SYSTEM_UI_FLAG_FULLSCREEN;  
uiFlags |= 0x00001000;
getWindow().getDecorView().setSystemUiVisibility(uiFlags); 
Log.d("Launcher_status_bar", "Launcher hideStatusBar()");

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值