5

I'm moving my app's ActionBar to ActionBarSherlock and I'm trying to customize the background with a tiled background. I'm testing my code on 2 real devices, one running Android 2.1 and the other running Android 4.0.4.

The code below is working on the ICS device (the background does repeat) but not on the Eclair one (the background is stretched instead of repeating). I've also tested this on Android 2.3 emulator and the background does not repeat too. It seems the tileMode="repeat" is only working on ICS.

themes.xml:

<style name="Theme.Opheodrys.Base" parent="Theme.Sherlock.Light">
    <item name="android:actionBarStyle">@style/Opheodrys.Widget.ActionBar</item>
    <item name="actionBarStyle">@style/Opheodrys.Widget.ActionBar</item>
</style>

<style name="Opheodrys.Widget.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
    <item name="android:background">@drawable/ab_background_pattern</item>
    <item name="background">@drawable/ab_background_pattern</item>
</style>

ab_background_pattern.xml:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/ab_background_tile"
    android:tileMode="repeat"
    tileMode="repeat" /> <!-- I've added this just in case, but it doesn't seem to be needed -->
Sabre
  • 4,131
  • 5
  • 36
  • 57
rfgamaral
  • 16,546
  • 57
  • 163
  • 275

1 Answers1

15

This is Android bug #15340 and not an ActionBarSherlock bug.

You can fix this with something similar to:

BitmapDrawable bg = (BitmapDrawable)getResources().getDrawable(R.drawable.bg_striped);
bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
getSupportActionBar().setBackgroundDrawable(bg);
Jake Wharton
  • 75,598
  • 23
  • 223
  • 230
  • After posting this question I've come across that bug and was looking for a fix on this particular case. Thanks for code. I assumed it was a problem with ActionBarSherlock because I have a similar drawable which is applied to the background of an ImageView and I never noticed it stretching... – rfgamaral Aug 22 '12 at 18:52
  • Future travelers: This is now automatically fixed by ABS. – Jake Wharton May 22 '13 at 18:41