简体   繁体   中英

Using the Material Theme colorPrimary status bar won't change

So I set in my theme:

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

nothing has changed , why?

I know that:

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

but: In this application works without problems:

AppCompat库将在Android 4.0上为状态栏着色

and myApp:

在此处输入图片说明

Try adding

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

If you want to change status bar color as written in http://developer.android.com/reference/android/view/Window.html#setStatusBarColor(int)

need import:

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

and next add this:

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM