3

I have found similar questions but the answers did not work. I do not want to change the colorPrimary.

The ActionBar is not a ToolBar, so it does not exist in the activity's layout XML. The following did not work, and the bakground was still set to colorPrimary.

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat">
        <!-- Customize your theme here. -->
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:statusBarColor">@color/colorBlack</item>
        <item name="android:colorBackground">@color/colorBlack</item>
    </style>

    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:backgroundStacked">@color/colorBlack</item>
        <item name="android:backgroundSplit">@color/colorBlack</item>
        <item name="android:background">@color/colorBlack</item>
    </style>
</resources>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>
Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135
  • Why you do not want to change the colorPrimary. While you want to change the color throught your app? – Xenolion Mar 19 '18 at 11:24
  • did you try this one https://stackoverflow.com/a/9249702/9287163 – krishank Tripathi Mar 19 '18 at 11:27
  • https://stackoverflow.com/questions/15747943/how-to-change-actionbar-color?noredirect=1&lq=1 – Sam Mar 19 '18 at 11:45
  • 1
    I want colorPrimary (which is very conspicuous) for something that needs user's attention such as the selected date of calendar. But the ActionBar is something that is always there and does not need to be conspicuous, so I want a dull colour for it. You may disagree on my reasoning, but that is just my opinion. – Damn Vegetables Mar 19 '18 at 15:27

1 Answers1

0

Programmatically you can do

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#YOUR_COLOR")));
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440