android從4.4開始可以嘗試對狀態欄的背景顏色進行改變,當然也可以設置爲透明,但經測試最終達到的效果是5.0以上有辦法全透明,4.4-5.0能半透明。其他顏色可隨意設置,具體方法是:
5.0設置全透明
if (Build.VERSION.SDK_INT >= 21) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
window.setNavigationBarColor(Color.TRANSPARENT);
}
4.4以上設置半透明
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintColor(Color.RED);
tintManager.setStatusBarTintEnabled(true);
}
有關Navigation的設置都是底部導航欄的設置。 注意<item name="android:fitsSystemWindows">true</item>的使用。 想要透明肯定是設置爲不設置,默認爲false,要沉浸的樣式(或者設置顏色)就要加上這個。
以上內容有借鑑:
http://blog.csdn.net/fengye810130/article/details/44461059
http://www.jianshu.com/p/f8374d6267ef
https://github.com/jgilfelt/SystemBarTint