Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(colorPrimaryDark) status bar color not working on android v21?

Tags:

android

I have added colorPrimaryDark on style.xml but no color affected on status bar android v21.

i have a custom toolbar where i use no action bar theme in style.xml code

if any solution please help me ?

style code:-

 <style name="AppTheme" parent="AppTheme.Base">
    <!-- Customize your theme here. -->
</style>

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

<style name="myCustomToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:textColorSecondary">@color/colorAccent</item>
</style>

style v21 :-

  <style name="AppTheme" parent="AppTheme.Base">
    <item name="android:colorPrimary">@color/colorPrimary</item>
    <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:colorAccent">@color/colorAccent</item>

    <item name="windowActionBar">true</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

Toolbar Code:-

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:elevation="4dp"
android:background="@color/colorPrimary"
android:popupTheme="@style/Base.ThemeOverlay.AppCompat.Light"
xmlns:android="http://schemas.android.com/apk/res/android" />

Main Layout Code

<android.support.design.widget.CoordinatorLayout 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=".MainActivity">

<LinearLayout
    android:fitsSystemWindows="true"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical">

    <include layout="@layout/custom_toolbar"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button1" />

</LinearLayout>


<android.support.design.widget.FloatingActionButton
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/fab"
    android:layout_gravity="right|bottom"
    android:src="@mipmap/ic_plus"
    android:onClick="fabClick"
    android:layout_marginRight="@dimen/fab_margin"
    android:layout_marginBottom="@dimen/fab_margin_bottom"
    fab:borderWidth="0dp"/>

like image 993
Manish Tiwari Avatar asked Nov 12 '15 07:11

Manish Tiwari


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. Step 3: In your MainActivity, add this code in your onCreate method.

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

Create a new styles.xml file in values-v21 and add following property in AppTheme.

<item name="android:statusBarColor">@color/colorPrimaryDark</item>

I'm having following AppTheme in styles.xml (v21)

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@color/colorPrimaryDark</item>
</style>
like image 126
Akhtar Khan Avatar answered Oct 01 '22 04:10

Akhtar Khan