Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In the Build Your First App tutorial, what is "actionbar_background" and how do I define it?

Tags:

android

I'm working through the Android Build Your First App tutorials, and I've got to Styling The Action Bar.

I created this themes.xml file as per the tutorial:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/actionbar_background</item>
</style>

My problem is, that I don't know how to define actionbar_background. Of course, I get the following error:

Error:(12, 41) No resource found that matches the given name (at 'android:background' with value '@drawable/actionbar_background').

I guessed that it is a colour, but how do I define it?

like image 588
user1725145 Avatar asked Jan 31 '26 08:01

user1725145


1 Answers

just as a quick "first build" thing you can change to a color code, like this:

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">#aaaaaa</item>
</style>

but in you can make it to be any color or drawable.

Colors are usually defined in a separate file like this:

colors.xml

<?xml version='1.0' encoding='UTF-8'?>
<resources>
    <color name="disabled_text">#9FFF</color>
    <color name="actionbar">#000</color>
    <color name="background">#111</color>
 ... etc

</resources>

and drawables are defined as .png files placed in your drawables-... folders, or define as XML files in the drawables folder.

then referenced on the styles like this:

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@color/disabled_text</item>
</style>

or for a actionbar_background.png in the drawables-... folders

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/actionbar_background</item>
</style>
like image 174
Budius Avatar answered Feb 01 '26 22:02

Budius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!