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

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


你可能感兴趣的:(隐藏状态栏时,整体布局不会往上挪的办法)