Jnr
Jnr

Reputation: 1664

Change App Bar Background Color

I'm struggling to override the default themes app bar color properly. When I use the android:actionBarStyle it changes the color but then the title text is missing.

<resources>
  <style name="ToolbarThemeStyle" parent="android:Theme.Material.Light">
    <item name="android:actionBarStyle">@style/ActionBarTitle.Background</item>
  </style>
  <style name="ActionBarTitle.Background" parent="">
    <item name="android:background">#8DC44E</item>
    <item name="android:titleTextStyle">@style/ActionBarTitle.Text</item>
  </style>
  <style name="ActionBarTitle.Text" parent="">
    <item name="android:textColor">#FFFFFF</item>
  </style>
</resources>

I've tried Replacing the Action Bar but I'm wondering if there's not a shorter and easier way.

Manifest:

<application android:label="Home Automation" android:icon="@mipmap/ic_launcher" android:theme="@android:style/Theme.Material.Light"    
  </application>

Activity:

[Activity(Label = "Label", MainLauncher = false, Theme = "@style/ToolbarThemeStyle", NoHistory =true)]

Upvotes: 1

Views: 3239

Answers (3)

Jnr
Jnr

Reputation: 1664

Thanks all for your replies. I thought I'd answer this myself whereas I've spent hours trying to figure this out.

The obvious solution was in this page under Using Custom Themes but I was getting the error "No resource found that matches the given name (android:color Primary)". Changing android:minSDKVersion=23 also did not work.

I went to Application Properties and set the "Compile using Android version" to the current targeting framework (i.e. API 23) instead of the maximum which was not installed yet set to API 25.

Upvotes: 1

Vikas Kumar
Vikas Kumar

Reputation: 143

This code should be in you style.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <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="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

And make sure you should have declared it in manifest.xml

<application
        android:name=".app.AppController"
        android:allowBackup="true"
        android:icon="@drawable/images"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"> 

Upvotes: 0

vishal
vishal

Reputation: 49

make sure are you setting theme to activity in menifest or xml. Here I am sharing my theme code you can refer.

 <style name="MaterialAppTheme" parent="Theme.AppCompat.Light">
        <!-- colorPrimary is used for the default action bar background -->
        <item name="colorPrimary">@color/white</item>
        <item name="android:textColorSecondary">@color/red</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

Upvotes: 0

Related Questions