O__O
O__O

Reputation: 970

Setting a background drawabe for actionbar in android

I need to set different background image for action bar for different fragments. I am using the v4 support package. But I am getting a white background instead of the given image.

Below is the code I have used.

getActivity().getActionBar().setBackgroundDrawable(getActivity().getResources().getDrawable(R.id.image));

and also

Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.image);
        BitmapDrawable actionBarBackground = new BitmapDrawable(getResources(), bMap);
        ActionBar bar = getActivity().getActionBar();
        bar.setBackgroundDrawable(actionBarBackground);

I have created this style and used it in the manifest for the activity

android:theme="@style/ActionBarTheme"

 <style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar">
 <item name="android:background">@drawable/image</item>
 </style>

 <style name="ActionBarTheme" parent="@android:style/Theme.Holo.Light">
 <item name="android:actionBarStyle">@style/MyActionBar</item>
 </style>

Upvotes: 0

Views: 5256

Answers (2)

mujeeb.omr
mujeeb.omr

Reputation: 499

try this one

getActivity().getActionBar().setBackgroundDrawable(getActivity().getResources().getDrawable(R.drawable.image));

Upvotes: 2

Tarun
Tarun

Reputation: 13808

<style name="CustomActivityTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <!-- other activity and action bar styles here -->
    </style>

    <!-- style for the action bar backgrounds -->
    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@drawable/actionbar_background</item>
    </style>

In your manifest file:

 <activity android:name=".activity"
                  android:theme="@style/CustomActivityTheme"/>

Upvotes: 0

Related Questions