Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Material: Status bar color won't change

I'm developing an simple app to test the material design. I'm using com.android.support:appcompat-v7:21.0.0 and my activity looks like:

public class MyActivity extends ActionBarActivity {    ... } 

The layout is defined as:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".MyActivity">      <android.support.v7.widget.Toolbar         xmlns:android="http://schemas.android.com/apk/res/android"         android:id="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="128dp"         android:minHeight="?attr/actionBarSize"         android:background="?attr/colorPrimaryDark"/> </LinearLayout> 

Now i defined my theme following material guidelines:

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">     <item name="colorPrimary">@color/colorPrimary500</item>     <item name="colorPrimaryDark">@color/colorPrimaryDark700</item> </style> 

I'd like to change the status bar color in pre Android 5 and set it to colorPrimaryDark but i can't find the way. I tried using:

getWindow().setStatusBarColor(..) 

but setStatusBar color is available from level 21. Why if i define a colorPrimaryDark in my theme and use appcompact the status bar doesn't change color? Anyone can help?

like image 663
FrancescoAzzola Avatar asked Oct 21 '14 21:10

FrancescoAzzola


People also ask

Can you change the color of the status bar android?

Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar.

How do I change my toolbar color on android?

Just go to res/values/styles.edit the xml file to change the color of action bar. Code for styles.

How do I change the color of my text bar in swift 5?

Go to Project -> Target , Then set Status Bar Style to Light . It makes status-bar white from the launch screen. Then set View controller-based status bar appearance equal to NO in Info.

How can I change my status bar style in Android?

To customize it, first pull down the slider bar from the top of the screen. Next, tap on the three vertical dots in the top right corner. Now click on Status bar. You're in.


1 Answers

The status bar is a system window owned by the operating system. On pre-5.0 Android devices, applications do not have permission to alter its color, so this is not something that the AppCompat library can support for older platform versions. The best AppCompat can do is provide support for coloring the ActionBar and other common UI widgets within the application.

like image 92
Alex Lockwood Avatar answered Sep 24 '22 10:09

Alex Lockwood