getSupportActionBar().setBackgroundDrawable does not works, is there a better way to change background color?

3,874 views
Skip to first unread message

Profete162

unread,
Nov 6, 2011, 10:41:02 AM11/6/11
to ActionBarSherlock
Hello all,

I just wanted to change to background color of the actionBar in a
simple way.
I don't want overcomplicated code and change layout of it.

This is what I tried without success:
getSupportActionBar().setBackgroundDrawable(new
ColorDrawable(R.color.action_bar_tint));

The result is an ACtionBar that stays black.

Is there a beter way or snippet to achieve this?

Profete162

unread,
Nov 6, 2011, 10:47:30 AM11/6/11
to ActionBarSherlock
More Info, as I cannot edit:

The doc is clear, that should work: http://developer.android.com/guide/topics/ui/actionbar.html

Styling the Action Bar

The Action Bar is the heading for your application and a primary
interaction point for users, so you might want to modify some of its
design in order to make it feel more integrated with your application
design. There are several ways you can do this if you wish.

For simple modifications to the ActionBar, you can use the following
methods:

setBackgroundDrawable()
Sets a drawable to use as the Action Bar's background. The drawable
should be a Nine-patch image, a shape, or a solid color, so the system
can resize the drawable based on the size of the Action Bar (you
should not use a fixed-size bitmap image).

Thank a lot for your help.

Jake Wharton

unread,
Nov 7, 2011, 6:14:10 PM11/7/11
to actionba...@googlegroups.com
I added the following line to the onCreate in the TitlesActivity class in the shakespeare sample which worked fine.

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xff550000));


device-2011-11-07-151317.png

Matt Kranzler

unread,
Dec 5, 2011, 2:45:39 PM12/5/11
to ActionBarSherlock
I'm having issues with getSupportActionBar().setBackgroundDrawable()
in version 3.4.0. I am using the abBackground attribute to set the
original background, but then if the device is in offline mode I am
changing the background. On Android 3.0+ this works fine and the
background changes when I go into offline mode and changes back when I
go online. However, with the support action bar when I call
setBackgroundDrawable() its as thought the original background is
overlaid on top of the background I am setting. The original
background doesn't go away, but when I call setBackgroundDrawable()
twice (offline mode, then back to online mode) it shows the offline
mode background with the online mode on top, and then the online mode
only (the offline mode is hiding). Any suggestions?

On Nov 7, 5:14 pm, Jake Wharton <jakewhar...@gmail.com> wrote:
> I added the following line to the onCreate in the TitlesActivity class in
> the shakespeare sample which worked fine.
>
> getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xff550000));
>
> [image: device-2011-11-07-151317.png]
>
> ---

> Jake Whartonhttp://about.me/jakewharton


>
> On Sun, Nov 6, 2011 at 7:47 AM, Profete162 <christophe.versi...@gmail.com>wrote:
>
>
>
>
>
>
>
> > More Info, as I cannot edit:
>
> > The doc is clear, that should work:
> >http://developer.android.com/guide/topics/ui/actionbar.html
>
> > Styling the Action Bar
>
> > The Action Bar is the heading for your application and a primary
> > interaction point for users, so you might want to modify some of its
> > design in order to make it feel more integrated with your application
> > design. There are several ways you can do this if you wish.
>
> > For simple modifications to the ActionBar, you can use the following
> > methods:
>
> > setBackgroundDrawable()
> > Sets a drawable to use as the Action Bar's background. The drawable
> > should be a Nine-patch image, a shape, or a solid color, so the system
> > can resize the drawable based on the size of the Action Bar (you
> > should not use a fixed-size bitmap image).
>
> > Thank a lot for your help.
>
>
>

>  device-2011-11-07-151317.png
> 34KViewDownload

Reply all
Reply to author
Forward
0 new messages