背景
- Android在
4.4
版本推出一個透明狀態(tài)欄
的概念,使手機(jī)頂部的狀態(tài)欄的顏色全透明。 - 在
5.0
版本推出了Material Design,可以修改狀態(tài)欄顏色
。 - 所以4.4之前的版本是無法設(shè)置狀態(tài)欄顏色的。
網(wǎng)易云音樂對比圖
對比圖
代碼實(shí)現(xiàn)
1 版本大于4.4
// 1.設(shè)置狀態(tài)欄透明,經(jīng)測試在代碼里直接聲明透明狀態(tài)欄更有效
WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
// 2.在布局文件中,添加屬性 android:fitsSystemWindows=“true",設(shè)置背景色。
2 版本5.0以上,在Theme中設(shè)置屬性colorPrimaryDark
的顏色
顏色設(shè)置說明