- 首先添加依賴.
compile ‘com.readystatesoftware.systembartint:systembartint:1.0.3’
- 将狀态欄設定為透明.
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//透明狀态欄 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
- 設定狀态欄顔色.
// 建立狀态欄的管理執行個體
SystemBarTintManager tintManager = new SystemBarTintManager(this);
// 激活狀态欄設定
tintManager.setStatusBarTintEnabled(true);
// 激活導航欄設定
tintManager.setNavigationBarTintEnabled(true);
// 設定一個顔色給系統欄
tintManager.setTintColor(Color.parseColor("#40C4FF"));
在顔色設定裡通過R.color.item好像不可以,該方法需要傳入一個string類型的顔色描述,R.xxx傳遞的是int的資源參數.
這樣的設定下,Activity回合标題欄重疊,還需要在布局檔案裡加上
android:fitsSystemWindows=”true”
android:clipToPadding=”true”
才可以正常的顯示.
然後..就沒有鳥.