Android 设置系统SystemUI 顶部StatusBar状态栏透明一体化

有两个文件

gemini_status_bar.xml(修改这个背景生效)

status_bar.xml

 

系统默认黑色状态:android:background="@drawable/system_bar_background"

 

xmlns:android=http://schemas.android.com/apk/res/android

xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"

    android:id="@+id/status_bar"

    android:background="#00000000"

    android:orientation="vertical"

    android:focusable="true"

    android:descendantFocusability="afterDescendants"

    android:fitsSystemWindows="true"

    >

NavigationBar透明修改这里

navigation_bar.xml

android/frameworks/base/policy/src/com/android/internal/policy/implPhoneWindowManager.java

/** {@inheritDoc} */

   @Override

   public int getSystemDecorLayerLw() {

             //modify system statusBar transparent lhwstart

             if(mStatusBar != null) return 0;

       //if(mStatusBar != null) return mStatusBar.getSurfaceLayer();

        //modify system statusBar transparent lhw end

       if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();

       return 0;

}

参考链接

http://blog.csdn.net/misly_vinky/article/details/12161075

 

这样修改的确能够把SystemUI StatusBar变成透明的但是有一个弊端就是会导致你的其他白色应用打开的时候,当前的StatusBar就会透明和白色混着一起导致看的很刺眼

 

SystemBarTintManager.java

Android 4.4 以上版本可以设置透明

         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {  
            setTranslucentStatus(true);  
            SystemBarTintManager tintManager = new SystemBarTintManager(this);  
            tintManager.setStatusBarTintEnabled(true);  
            tintManager.setStatusBarTintResource(R.color.top_bg_color);//通知栏所需颜色
        } 
         @TargetApi(19)   
    private void setTranslucentStatus(boolean on) {  
        Window win = getWindow();  
        WindowManager.LayoutParams winParams = win.getAttributes();  
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;  
        if (on) {  
            winParams.flags |= bits;  
        } else {  
            winParams.flags &= ~bits;  
        }  
        win.setAttributes(winParams);  
    }
我自己处理的方法,就是通过Launcher去发送连个广播,去处理,去监听Launcher的生命周期会发现
当你开启其他应用的时候,执行的是onPause()方法,当返回Launcher的时候执行的是onRestart()方法, /frameworks/base/package/SystemUI/…. PhoneStatusBar.java
//sendBroadcast change systemUI statusbar color start 
           Intent intent=new Intent("change_statusbar_black");
           sendBroadcast(intent);
          
所以我在onPause里通知statusbar去变成黑色,然后onRestart去通知变成透明色,当然这样就会导致刚开机的时候Launcher是黑色的,所以要去修改gemini_status_bar.xml或者是
status_bar.xml
的默认背景色是透明的
  PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        mBroadcastReceiver.onReceive(mContext,
                new Intent(pm.isScreenOn() ? Intent.ACTION_SCREEN_ON : Intent.ACTION_SCREEN_OFF));
 
        // receive broadcasts
// receive broadcasts
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        filter.addAction(Intent.ACTION_SCREEN_ON);
        filter.addAction(ACTION_DEMO);
//add action to change statusbar color start
        filter.addAction("change_statusbar_transparent");
        filter.addAction("change_statusbar_black");
       //add action to change statusbar color end
        context.registerReceiver(mBroadcastReceiver, filter);
 
 
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
 
public void onReceive(Context context, Intent intent) {
            if (DEBUG) Log.v(TAG, "onReceive: " + intent);
            String action = intent.getAction();
            Xlog.d(TAG, "onReceive, action=" + action);
            if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
                 int flags = CommandQueue.FLAG_EXCLUDE_NONE;
                if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
                    String reason = intent.getStringExtra("reason");
                    if (reason != null && reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) {
                        flags |= CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL;
                    }
                }
                animateCollapsePanels(flags);
            }
 //add onReceive to change statusbar color start 
         else if("change_statusbar_transparent".equals(action)){
                                    Log.e("LHW", "This transparent:");
              mStatusBarView.setBackgroundColor(android.R.color.transparent);
                            
 
                          }    
else if("change_statusbar_black".equals(action)){
                          
                                   Log.e("LHW", "This black:");
 
                   mStatusBarView.setBackgroundColor(android.R.color.black);    
                    
                          }
                          //add onReceive to change statusbar color end    

你可能感兴趣的:(Android,MTK开发笔记集)