1. 程式人生 > >android狀態列顏色和ToolBar保持一致

android狀態列顏色和ToolBar保持一致

為了使狀態列顏色和ToolBar保持一致保持一致好看些,就需要下面的簡單配置。

1、在當前的Activity中程式碼動態設定:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags
); }

2、在xml佈局的toolbar中加入下面一行程式碼:

android:fitsSystemWindows="true"

效果圖:


OK,這樣就行了。