Plynie
Plynie

Reputation: 53

Change background color of an android actionbar, base tutorial

I'm trying to change the ActionBar color of a New Android Application made by Eclipse wizard following the android tutorial (here), but i got several problems.

I set minSdkVersion to 10 (it should be android 2.1 or so).

When i paste this code into themes.xml (as said by the tutorial):

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

        <!-- Support library compatibility -->
        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
           parent="@style/AppTheme">
        <item name="android:background">#FFFFFF</item>

        <!-- Support library compatibility -->
        <item name="background">#FFFFFF</item>
    </style>
</resources>

Eclipse give to me those errors:

I modded little things (Base theme and Color), however the clean code is in the tutorial.

My Styles.xml is here:

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

What's the problem?

Upvotes: 4

Views: 11399

Answers (1)

Raghunandan
Raghunandan

Reputation: 133560

To use action bar below api level 11 you need to reference app compact (from the support library) in your project.

Your class needs to extends ActionBarActivity and you need to use Theme.AppCompat.

http://developer.android.com/guide/topics/ui/actionbar.html

Also check this

http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html

Or you need to use ActionBarSherlock

http://actionbarsherlock.com/

Upvotes: 5

Related Questions