当前位置:   article > 正文

Android7.1 动态显示和隐藏导航栏和状态栏 广播_android 设置状态栏覆盖在布局之上,并动态的显示和隐藏状态栏

android 设置状态栏覆盖在布局之上,并动态的显示和隐藏状态栏
由于公司项目需要动态显示和隐藏导航栏和状态栏,所以就需要从底层代码加入广播命令,下面是实际操作过程。


一、文件路径	
       /frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
	   在源码中增加如下代码,保存后重新编译,然后用adb shell am -a "..........."命令测试,
	   例如:adb shell am -a "lyzk.intent.systemui.hidenavigation"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
private int mNavigationIconHints = 0;
    private HandlerThread mHandlerThread;

    //Add By LYZK 2021/6/29
    private static final String SHOW_NAVIGATION = "lyzk.intent.systemui.shownavigation";
    private static final String HIDE_NAVIGATION = "lyzk.intent.systemui.hidenavigation";
    private static final String SHOW_STATUSBAR = "lyzk.intent.systemui.showstatusbar";
    private static final String HIDE_STATUSBAR = "lyzk.intent.systemui.hidestatusbar";
    //End Add

    // ensure quick settings is disabled until the current user makes it through the setup wizard
    private boolean mUserSetup = false;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
demoFilter.addAction(ACTION_DEMO);
        context.registerReceiverAsUser(mDemoReceiver, UserHandle.ALL, demoFilter,
                android.Manifest.permission.DUMP, null);

        //Add By LYZK 2021/6/29
        IntentFilter carfilter = new IntentFilter();
        carfilter.addAction(SHOW_NAVIGATION);
        carfilter.addAction(HIDE_NAVIGATION);
        carfilter.addAction(SHOW_STATUSBAR);
        carfilter.addAction(HIDE_STATUSBAR);
        context.registerReceiverAsUser(carBroadcastReceiver, UserHandle.ALL, carfilter, null, null);
        //End Add

        // listen for USER_SETUP_COMPLETE setting (per-user)
        resetUserSetupObserver();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
}, cancelAction, afterKeyguardGone);
    }
    //Add By LYZK 2021/6/29
    private BroadcastReceiver carBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.e(TAG, "zjy--onReceive: " + intent);
            String action = intent.getAction();
            if (HIDE_NAVIGATION.equals(action)) {
                if (mNavigationBarView == null) return;

                mWindowManager.removeViewImmediate(mNavigationBarView);
                mNavigationBarView = null;
            }else if (SHOW_NAVIGATION.equals(action)) {
                if (mNavigationBarView != null) return;
               createNavigationBarView(context);
               addNavigationBar();
            }else if(HIDE_STATUSBAR.equals(action)) {
               //mStatusBarView.setVisibility(View.GONE);
               mStatusBarWindow.setVisibility(View.GONE);
           }else if(SHOW_STATUSBAR.equals(action)) {
               //mStatusBarView.setVisibility(View.VISIBLE);
               mStatusBarWindow.setVisibility(View.VISIBLE);
       
           }
        }
    };
    //End Add
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
}
        mContext.unregisterReceiver(mBroadcastReceiver);
        mContext.unregisterReceiver(mDemoReceiver);
        //Add By LYZK 2021/6/30
        mContext.unregisterReceiver(carBroadcastReceiver);
        //End Add
        mAssistManager.destroy();

        final SignalClusterView signalCluster =
                (SignalClusterView) mStatusBarView.findViewById(R.id.signal_cluster);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

先检测一下adb 是否正常工作

C:\Users\Administrator>adb devices
List of devices attached
GB8ZADV49V      device
  • 1
  • 2
  • 3

发送隐藏导航栏广播

adb shell am -a "lyzk.intent.systemui.hidenavigation"
  • 1

发送隐藏状态栏广播

adb shell am -a "lyzk.intent.systemui.hidestatusbar"
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/791067
推荐阅读
相关标签
  

闽ICP备14008679号