Android7.1 高通平台 状态栏和导航栏的隐藏与显示

客户需求:在客户apk的一个或几个页面隐藏状态栏和导航栏,滑动时不显示出来。

源码位置:/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

MyBroadReceiver receiver = null;
    @Override
    public void createAndAddWindows() {
        Log.e("hdz","___________createAndAddWindows()");
        receiver = new MyBroadReceiver();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("StatusAndNavigationBar****");
        intentFilter.addAction("StatusAndNavigationBar****");
        mContext.registerReceiver(receiver,intentFilter);
        addStatusBarWindow();
    }

    private class MyBroadReceiver extends BroadcastReceiver{

        @Override
        public void onReceive(Context context, Intent intent) {
            Log.e("hdz","___________action : " + intent.getAction());
            if(intent.getAction().equals("StatusAndNavigationBar****")){//显示状态栏
                addStatusBarWindow(true);
            }else{//隐藏状态栏
                addStatusBarWindow(false);
            }
        }
    };

    private void addStatusBarWindow() {
        makeStatusBarView();
        mStatusBarWindowManager = new StatusBarWindowManager(mContext);
        mRemoteInputController = new RemoteInputController(mStatusBarWindowManager,
                mHeadsUpManager);
        mStatusBarWindowManager.add(mStatusBarWindow, getStatusBarHeight());  
    }

    private void addStatusBarWindow(boolean flag) {
        if(!flag){
            mStatusBarView.setVisibility(View.GONE);
            removeNavigationBar();
        }else{
            mStatusBarView.setVisibility(View.VISIBLE);
            addNavigationBar();
        }
    }

我在此是通过接收apk发出的广播的形式进行动态控制的,仅供参考,谢谢!