ActionBar background image

rnoway picture rnoway · May 2, 2011 · Viewed 67.5k times · Source

I've inherited the Holo Light Theme and customized the background of the ActionBar with the following:

Content of styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ActionBar" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">@drawable/actionbar_background</item>
</style>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBar</item>
</style>
</resources>

Content of actionbar_background.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@raw/actionbar_background"
android:tileMode="repeat" />

Instead of being repeated, the image is stretched, any idea of why android:tileMode="repeat" is not applied?

Thanks in advance

Answer

rnoway picture rnoway · May 3, 2011

Ok, thanks to Romain Guy on #android-dev IRC channel, it's a known bug on honeycomb / Android 3.0 which will be fixed on the next release. Since then, the only solution is do it from code, and it works :-)

 final ActionBar actionBar = getActionBar(); 
 BitmapDrawable background = new BitmapDrawable (BitmapFactory.decodeResource(getResources(), R.raw.actionbar_background)); 
 background.setTileModeX(android.graphics.Shader.TileMode.REPEAT); 
 actionBar.setBackgroundDrawable(background);