使用Material Theme colorPrimary状态栏不会发生变化

时间:2014-11-13 09:53:16

标签: android android-studio statusbar android-appcompat material-design

所以我设置了我的主题:

<item name="colorPrimaryDark">@color/indigo_50</item>

没有任何改变,为什么?

我知道:

On older platforms, AppCompat emulates the color theming where possible. At the moment this is limited to coloring the action bar and some widgets.

但: 在这个应用程序中工作没有问题:

 the AppCompat lib will color status bars on Android 4.0

和myApp:

enter image description here

2 个答案:

答案 0 :(得分:0)

尝试添加

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

如果要更改状态栏颜色,请写入 http://developer.android.com/reference/android/view/Window.html#setStatusBarColor(int)

答案 1 :(得分:0)

需要导入:

compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'    

然后添加:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                Window w = getWindow(); // in Activity's onCreate() for instance
                w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
                w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
SystemBarTintManager tintManager = new SystemBarTintManager(this);
// enable status bar tint
tintManager.setStatusBarTintEnabled(true);
// enable navigation bar tint
tintManager.setNavigationBarTintEnabled(true);


 // set a custom tint color for all system bars
 tintManager.setTintColor(Color.BLUE);