android 动态显示状态栏和导航栏

开始的时候在网上搜过很多方法,包括
1.通过命令移除SystemUI.apk放到一个文件夹中,然后重新启动com.systemui.SystemUIService这个服务

如果想恢复就把SystemUI.apk移到/system/app/下并且重新启动com.systemui.SystemUIService这个服务。

2.通过不断查杀com.android.systemui(这种暴力的方式不知道有什么后果)
这种方式可以使用如下命令搜出进程号:
process = ps | grep -i "systemui"|busybox awk 'BEGIN {FS=" "} {print $2}'
然后kill $process
不过现象是总是会回到锁屏界面,可以尝试使用定时器每五百毫秒进行一次查杀。

3.还有一种是使用标准的api ,在apk中去使用这个方法去隐藏,不过下拉之后就会显示出状态栏。
猜想:这个要结合禁止下拉一起使用,方才可以。

   public void is_full(boolean enable) {
         if (enable) {
         WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN ;
//      lp.flags |= WindowManager.LayoutParams.TYPE
        getWindow().setAttributes(lp);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
         } else {
        WindowManager.LayoutParams attr = getWindow().getAttributes();
         attr.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
         getWindow().setAttributes(attr);
         getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
         }
         }

还有一个api是使用如下方法,不过也没有效果,只能实现如图库,视频等的“不触摸全屏显示”:
(具体更多的flag请自行搜索)
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

最后成功的方法是:

在PhoneStatusBar.java中添加广播接受器,动态地add 和 remove 相应的视图。
在其中添加了静止下拉的操作,和禁掉了一些StatusBar的UI,并隐藏了NavigationBar。
也算勉强达到了效果。

完整的补丁如下,本人是在4.4的平台上操作的,仅供参考(不同平台请移植):

$ git diff packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index a4d1b5f..f21c8ce 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -38,6 +38,7 @@ import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.SharedPreferences;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.database.ContentObserver;
@@ -254,6 +255,13 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode {
     int[] mAbsPos = new int[2];
     Runnable mPostCollapseCleanup = null;

+    //modified by 3110 hide or display navbar
+    private boolean mDisplayNav = true;
+    private final String PREF_NAME = "systemui";
+    private final String PREF_DISPLAY_NAV = "display_nav";
+    private SharedPreferences mSharePref;
+
+
     // for disabling the status bar
     int mDisabled = 0;

@@ -279,6 +287,29 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode {
         }
     };

+    //modified by 3110 hide and display NavBar
+    private BroadcastReceiver mBroadcastReceiver1 = new BroadcastReceiver() {
+       @Override
+       public void onReceive(Context context, Intent intent) {
+               String action = intent.getAction();
+              //thisone
+              // if (isOrderedBroadcast()) {
+                       if (action.equals("MyRecv_action")) {
+                      Log.d("hhhh","now i come");
+                      Log.v("hhhh","2222222");
+                       String cmd = intent.getStringExtra("cmd");
+                       if(cmd.equals("hide")){
+                               removeNavigationBar();
+                       }else if(cmd.equals("show")){
+                               addNavigationBar();
+                       }
+                       }
+                //       this.abortBroadcast();
+              // }
+       }
+    };
+
+
     // ensure quick settings is disabled until the current user makes it through the setup wizard
     private boolean mUserSetup = false;
     private ContentObserver mUserSetupObserver = new ContentObserver(new Handler()) {
@@ -348,7 +379,16 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode {

         super.start(); // calls createAndAddWindows()

-        addNavigationBar();
+       // addNavigationBar();
+
+       //modified by 3110
+       IntentFilter filter1 = new IntentFilter();
+       filter1.addAction("MyRecv_action");
+       mContext.registerReceiver(mBroadcastReceiver1, filter1);
+
+       if(mDisplayNav){
+               addNavigationBar();
+       }

         // Lastly, call to the icon policy to install/update all the icons.
         mIconPolicy = new PhoneStatusBarPolicy(mContext);
@@ -544,6 +584,17 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode {
         mNetworkController.addSignalCluster(signalCluster);
         signalCluster.setNetworkController(mNetworkController);

+        //modified by 3110 rick:put display nav values into shares
+        mSharePref = mContext.getSharedPreferences(PREF_NAME,
+                               Context.MODE_PRIVATE);
+        if(mSharePref != null){
+               mDisplayNav = mSharePref.getBoolean(PREF_DISPLAY_NAV, true);
+               Log.d("RickOne____makeStatusBarView","===="+"mDisplayNav="+mDisplayNav);
+        }else{
+               Log.d("RickOne____makeStatusBarView_null","===="+"mDisplayNav="+mDisplayNav);
+        }
+
+
         final boolean isAPhone = mNetworkController.hasVoiceCallingFeature();
         if (isAPhone) {
             mEmergencyCallLabel =
@@ -800,13 +851,59 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode {

     // For small-screen devices (read: phones) that lack hardware navigation buttons
     private void addNavigationBar() {
+        final int mode = StatusBarManager.DISABLE_NONE;
+
         if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + mNavigationBarView);
         if (mNavigationBarView == null) return;

         prepareNavigationBarView();
+        
+       //modified by 3110
+        mDisplayNav = true;
+       if(mSharePref != null){
+               mSharePref.edit().putBoolean(PREF_DISPLAY_NAV, mDisplayNav)
+               .commit();
+       }

         mWindowManager.addView(mNavigationBarView, getNavigationBarLayoutParams());
-    }
+        //addStatusBarWindow();
+       
+       mHandler.post(new Runnable() {
+
+                                          @Override
+                                          public void run() {
+
+                                               disable(mode);
+                                               }
+                                       });
+
+       
+    }
+
+       //modified by 3110
+     private void removeNavigationBar(){
+       
+       final int mode = StatusBarManager.DISABLE_EXPAND |StatusBarManager.DISABLE_SYSTEM_INFO;
+       if(mNavigationBarView == null){
+               return;
+       }
+       mDisplayNav = false;
+       if(mSharePref != null){
+               mSharePref.edit().putBoolean(PREF_DISPLAY_NAV, mDisplayNav)
+               .commit();
+       }
+       mWindowManager.removeView(mNavigationBarView);
+       //mWindowManager.removeView(mStatusBarView);
+       mHandler.post(new Runnable() {
+                                               
+                                          @Override
+                                          public void run() {
+                                                   
+                                               disable(mode);
+                                               }
+                                       }); 
+       }
+

     private void repositionNavigationBar() {
         if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return;
@@ -1410,8 +1507,14 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode {

         mExpandedVisible = true;
         mPile.setLayoutTransitionsEnabled(true);
-        if (mNavigationBarView != null)
-            mNavigationBarView.setSlippery(true);
+        
+       //modified by 3110
+       //if (mNavigationBarView != null)
+        //    mNavigationBarView.setSlippery(true);
+       //modified by 3110
+       if (mNavigationBarView != null && mDisplayNav){
+            mNavigationBarView.setSlippery(mDisplayNav);
+        }

         updateCarrierLabelVisibility(true);

测试代码:

$adb remount && adb shell
//显示诸多栏
$am broadcast -a MyRecv_action --es cmd "show"
//隐藏诸多栏
$am broadcast -a MyRecv_action --es cmd "hide"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值