Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with changing ActionBar background - Android

Tags:

android

Hey guys I am newer to Android development and I am working on changing my ActionBar's background. When adding the following in my themes.xml file within res->values

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

I receive this error message:

error: Error: No resource found that matches the given name (at 'android:background' with value '@drawable/
 actionbar_background').

I am not positive why I am receiving this message and could use a hand.

David

like image 277
David Biga Avatar asked Jan 16 '26 21:01

David Biga


2 Answers

Just guessing, but my bet is that you don't have any drawable named actionbar_background.png

Double check for possible typos in your png resource. It should be in any drawable folder. Or you could just set a color with.-

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

Please notice that hardcoding values is a bad practice. If you finally go for a background color, you should consider creating a resource item for that color, in a separate resource file (i.e. colors.xml)

<color name="red">#FF0000</color>

And reference it with in your item style with @color/red

like image 142
ssantos Avatar answered Jan 19 '26 20:01

ssantos


You can use it when activity created. (onCreate)

ActionBar bar = getActionBar();
//for color
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00C4CD")));
//for image
bar.setBackgroundDrawable(getResources().getDrawable(R.drawable.settings_icon));
like image 20
Melih Mucuk Avatar answered Jan 19 '26 18:01

Melih Mucuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!