Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionBarSherlock background does not repeat on pre ICS versions

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 -->
like image 404
rfgamaral Avatar asked Aug 22 '12 18:08

rfgamaral


1 Answers

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);
like image 61
Jake Wharton Avatar answered Oct 02 '22 06:10

Jake Wharton