2

I am trying to change the background color of the ActionBar of my app.

I tried the following changes,

Reference link

In style.xml file, I added "MyTheme" and "ActionBarBackground" like below.

    <resources>

    <!--
        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>
    <style name="MyTheme" parent="AppBaseTheme">
        <item name="android:actionBarStyle">@style/ActionBarBackground</item>
    </style>
    <style name="ActionBarBackground" parent="AppBaseTheme">
        <item name="android:background">#00008b</item>
    </style>

</resources>

And then,

Manifest file, I added for that particular activity like below,

<activity android:name="LoginActivity" android:theme="@style/ActionBarBackground">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

What happens is, It changes to blue color for the background of entire activity view rather than to change color just to the action bar.

Could someone advise, what i’m doing wrong here.

Community
  • 1
  • 1
Stella
  • 1,728
  • 5
  • 41
  • 95

3 Answers3

5

I changed it color like this.

you can try this.

ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(0xFF160203));

Add this in your activity class.

anuruddhika
  • 1,549
  • 8
  • 26
  • 40
  • I tried like this, ActionBar actionBar = getActionBar(); actionBar.setBackgroundDrawable(new ColorDrawable(0x00008b)); But, I'm seeing white background of action bar in this activity layout. – Stella Mar 31 '14 at 08:35
  • I changed the value to 0xff005fbf, and it is showing blue as expected. Thank you! – Stella Mar 31 '14 at 08:43
  • mine became transparent instead. I was rather trying a fading actionbar effect too, maybe something screwed up. Any idea how do I do it @anuruddhika ? – Learner Always Oct 18 '14 at 14:01
1

Create your style here: ActionBar Style Generator. A zip file will be generated containing a bunch of files. Copy them into the proper resource folders.

If you are curious, you can go and look at the generated files to see how best to style the action bar through application styles and themes.

Karakuri
  • 38,365
  • 12
  • 84
  • 104
0

On your Activity code, you can put these instruction in your onCreate() method:

getActionBar().setBackgroundDrawable(new ColorDrawable(this.getResources().getColor(resId_color)));

When your resid_color is the color defined in your colours.xml file.

jmrodrigg
  • 600
  • 6
  • 24