Search code examples
androidxmlstatusbar

Activity's status bar color is different for no apparent reason


I've created a new activity and for some reason, when it is used, it uses a different color in the status bar. What's strange is that in the "design" preview it renders the correct color.

Below are two screen shots, the darker color is the correct color.

Incorrect enter image description here Correct enter image description here

The themes are the same as the other .xml layouts, so I'm having trouble really figuring out where this error is coming from. Below is the code for the layout:

activity_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.brewguide.android.coffeebrewguide.MenuActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            />

    </android.support.design.widget.AppBarLayout>

<LinearLayout
    android:id="@+id/myfragment"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>

I'm not sure what other code would be useful to include for diagnosing this.


Edit:

styles.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="DescriptionTextView">
    <item name="android:textColor">@color/colorPrimaryDark</item>
    <item name="android:background">@color/mainBackground</item>
</style>

<!--style for the start button in the clock view layout-->
<style name="AppTheme.Button.Start" parent="Widget.AppCompat.Button.Colored">
    <item name="colorButtonNormal">@color/complimentaryLeft</item>
    <item name="android:textColor">@color/cardview_dark_background</item>
</style>

<!--style for the stop button in the clock view layout-->
<style name="AppTheme.Button.Stop" parent="Widget.AppCompat.Button.Colored">
    <item name="colorButtonNormal">@color/colorPrimary</item>
    <item name="android:textColor">@color/cardview_dark_background</item>
</style>

<!--style for the reset button in the clock view layout-->
<style name="AppTheme.Button.Reset" parent="Widget.AppCompat.Button.Colored">
    <item name="colorButtonNormal">@color/colorAccent</item>
    <item name="android:textColor">@color/cardview_light_background</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@android:color/white</item>
</style>


Solution

  • Managed to programatically set the color using the following line:

    getActivity().getWindow().setStatusBarColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
    

    I would prefer to have this done in the .xml however.