在4.4以上的手機上運行網易新聞和QQ都會出現java
與標題欄同色的通知欄android
設置方法有兩種:佈局
1.增長values-v19文件夾編寫style.xml
ui
<style name="Theme.Timetodo" parent="@android:style/Theme.Holo.Light"> <!-- 透明狀態欄 --> <item name="android:windowTranslucentStatus">true</item> <!-- 透明導航欄 --> <item name="android:windowTranslucentNavigation">true</item> </style>
在manifest.xml中引用該stylethis
2.在Activity的onCreate中.net
if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { // 透明狀態欄 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // 透明導航欄 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); }
上面的兩個方法狀態欄顏色能夠在佈局的根目錄設置顏色。code
3.下載http://www.oschina.net/code/snippet_2406628_51101
xml
主頁中增長代碼圖片
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); // 使用顏色資源 tintManager.setStatusBarTintResource(R.color.title_bg); // 使用圖片資源 // tintManager.setStatusBarTintDrawable(getResources().getDrawable(R.drawable.ic_top_title_background)); }
最後在佈局文件中的根控件中使用android:fitsSystemWindows="true"不然整個整個佈局會和狀態欄有重疊ip