Android, Style ActionBar with Background Image & Background Colour

401 Views Asked by At

styles.xml

<resources>
    <style name="CustomTheme" parent="Theme.AppCompat.Light">
        <item name="android:actionBarStyle">@style/CustomBar</item>
        <item name="actionBarStyle">@style/CustomBar</item>
    </style>

    <style name="CustomBar" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:background">@color/black</item>
        <item name="android:src">@drawable/home</item>
        <item name="background">@color/black</item>
        <item name="src">@drawable/home</item>
    </style>
</resources>

The Above code doesn't work as android:src is not found, however i wish to achieve the intended effect of this. I have a company logo that i want to use as the action bar main image, but don't want to use static image for full background colouring. The logo image, @drawable/home has a transparent background.

How would i style the action bar to include an image as well as a background colour?

1

There are 1 best solutions below

0
On

I don`t know that we have src, here is the code what worked for me: to set the image this is what I use:

  <item name="android:background">@drawable/headerflowerimage</item>

Please find the whole code here:

 <!-- the theme applied to the application or activity -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">



    <item name="android:actionBarStyle">@style/SActionBar</item>
    <!--- Support library compatibility-->
    <item name="actionBarStyle">@style/SActionBar</item>


    <item name="android:actionBarTabStyle">@style/STabBars</item>
    <!-- Support library compatibility -->
    <item name="actionBarTabStyle">@style/STabBars</item>

</style>

<!-- ActionBar tabs styles -->
<style name="STabBars" parent="@style/Widget.AppCompat.ActionBar.TabView">
    <!-- tab indicator -->
    <item name="android:background">@color/tabbar_background</item>
    <item name="android:backgroundStacked">@color/background_material_light</item>
    <item name="android:actionBarTabTextStyle">@color/greyrish_s</item>

    <!-- Support library compatibility -->
    <item name="background">@color/tabbar_background</item>
    <item name="backgroundStacked">@color/background_material_light</item>
    <item name="actionBarTabTextStyle">@color/greyrish_s</item>
</style>

<!-- ActionBar styles -->
<style name="SActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/headerflowerimage</item>
    <item name="android:titleTextStyle">@style/sTitleColor</item>
    <item name="android:displayOptions">showTitle</item>

    <!-- Support library compatibility -->
    <item name="background">@drawable/headerflowerimage</item>
    <item name="titleTextStyle">@style/sTitleColor</item>
    <item name="displayOptions">showTitle</item>

</style>