systemui状态栏半透明修改

 1、syetemui状态栏半透明修改主要布局文件为status_bar.xml

  可以在根布局加个半透明:android:background="#80000000"

  修改super_status_bar.xml中的如下为。

  修改前:

 

  修改后:


     
     
    


 

 2、具体实现需要依靠底层,需要在底层加广播,像锁屏或activity类中,在systemui中主要修改PhoneStatusBar.java这个类

    public static final String SCREEN_LOCK =  "android.keygard.screen_lock";
    public static final String SCREEN_UNLOCK =  "android.keygard.screen_unlock";
    public static final String SCREEN_UNLOCK_APP =  "android.keygard.screen_unlock_app";

    private IntentFilter mIntentFilter;
    LinearLayout statusbar;

    private BroadcastReceiver mWallpaperReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
         
            if (SCREEN_LOCK.equals(intent.getAction())) {
                System.out.println("SCREEN_LOCK.......");
                statusbar.setBackground(WallpaperManager.getInstance(context).getLockScreenTitleDrawable());
          
            } else if (SCREEN_UNLOCK.equals(intent.getAction())) {
                System.out.println("SCREEN_UNLOCK.......");
                statusbar.setBackground(null);
            
            } else if (SCREEN_UNLOCK_APP.equals(intent.getAction())){
                System.out.println("SCREEN_UNLOCK_APP.......");
               statusbar.setBackgroundResource(R.drawable.status_bar_background);        
            }
        }
    };

    statusbar = (LinearLayout) mStatusBarWindow.findViewById(R.id.statusbar_background); 

    mIntentFilter = new IntentFilter();
    mIntentFilter.addAction(SCREEN_LOCK);
    mIntentFilter.addAction(SCREEN_UNLOCK);
    mIntentFilter.addAction(SCREEN_UNLOCK_APP);
    context.registerReceiver(mWallpaperReceiver, mIntentFilter);

底层可以在锁屏与activity处发广播:

1、锁屏

   在类com.android.internal.policy.impl.keyguard.KeyguardViewManager.java中定义了两个静态变量,如下。

   

public static final String SCREEN_LOCK =  "android.keygard.screen_lock";
    public static final String SCREEN_UNLOCK =  "android.keygard.screen_unlock";

      /** 显示锁屏界面   
     * Hides the keyguard view
     */
    public synchronized void hide() {

        ................

        Intent showTitleBackIntent = new Intent(SCREEN_UNLOCK);
        mContext.sendBroadcast(showTitleBackIntent);

   }

   在com.android.internal.policy.impl.keyguard.KeyguardViewBase.java中

   public KeyguardViewBase(Context context, AttributeSet attrs) {
        super(context, attrs);
        resetBackground();
    }

   public void resetBackground() {

         Intent showTitleBackIntent = new Intent(KeyguardViewManager.SCREEN_LOCK);
         try{
               mContext.sendBroadcast(showTitleBackIntent);
          }catch (Exception e) {
          e.printStackTrace();
        }
        postInvalidate();

    }

    public class KeyguardHostView extends KeyguardViewBase{

         public KeyguardHostView(Context context, AttributeSet attrs) {
                 super(context, attrs);//调用KeyguardViewBase的构造方法

         }  

     }

上述的action也可以使用 public static final String SCREEN_LOCK =  Intent.ACTION_SCREEN_OFF;

其在com.android.internal.policy.impl.GlobalActions.java的构造方法中也发布了此广播

       

 IntentFilter filter = new IntentFilter();
 filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
 filter.addAction(Intent.ACTION_SCREEN_OFF);
 filter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
 context.registerReceiver(mBroadcastReceiver, filter);

2、frameworks\base\core\java\android\app\Activity.java中定义两广播:

  

 public static final String SCREEN_UNLOCK =  "android.keygard.screen_unlock";
 public static final String SCREEN_UNLOCK_APP =  "android.keygard.screen_unlock_app";

   在onresume方法中:

  protected void onResume() {
       .........

        try{
              if(getPackageName().equals("com.android.launcher") ){
                   Intent showTitleBackIntent = new Intent(SCREEN_UNLOCK);
                   sendBroadcast(showTitleBackIntent);
              }else{
                  Intent showTitleBackIntent = new Intent(SCREEN_UNLOCK_APP);
                  sendBroadcast(showTitleBackIntent);
              }
          }catch (Exception e) {
             e.printStackTrace();
          }
        }
 }

做到这一步差不多就成功了,但是如果你的状态栏非半透明的,而是某个图片,这时,你会发现在下拉托盘时再锁屏,此时,亮屏时会出现半透明的黑色出现在状态栏上

查看xml文件status_bar.xml得知,其是自定义的布局:

因此去com.android.systemui.statusbar.phone.PhoneStatusBarView.java中查看

 

public void panelExpansionChanged(PanelView panel, float frac) {

    .......

    if (frac <= 0) {
         // mBar.mStatusBarWindow.setBackgroundColor(0); //deleted by fengluping 2014.05.13
     } else {
        final float k = (float)(1f-0.5f*(1f-Math.cos(3.14159f * Math.pow(1f-frac, 2f))));
        final int color = (int) ((mScrimColor >>> 24) * k) << 24 | (mScrimColor & 0xFFFFFF);
       // mBar.mStatusBarWindow.setBackgroundColor(color); //deleted by fengluping 2014.05.13
      }

   ......

}


 

很明显上述两句在托盘下拉状态改变时,给其附了颜色,此时我们注销掉就可以了。

 

 

你可能感兴趣的:(systemui)