In the Build Your First Application tutorial, what is actionbar_background and how do you define it?

I am working on Android Build Your First tutorials and I need Styling The Action Bar.

I created this themes.xml file according to 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 I don't know how to determine actionbar_background

. Of course I am getting the following error:

Error: (12, 41) Resource not found that matches the specified name (at 'android: background' with value '@ drawable / actionbar_background').

I guessed it was a color, but how do you define it?

+3


source to share


2 answers


as a quick "first build" that you can change to color code like:

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

      

but you can make it any color

or drawable

.

Colors are usually defined in a separate file as follows:

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 are drawables

defined as .png

files placed in your folders drawables-...

, or defined as XML

files in a folder drawables

.

then the styles are referenced 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 actionbar_background.png in folders drawables-...

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

      

+12


source


Create a drawable / actionbar_background.xml file using the code below:



<?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
           <solid android:color="#ffcf6413"/>
        </shape>
    </item>
    <item
        android:bottom="2dp">
        <shape android:shape="rectangle">
            <solid android:color="#fff4842c"/>
        </shape>
    </item>
</layer-list>

      

0


source







All Articles