ActionBarSherlock background does not repeat on pre ICS versions

ⅰ亾dé卋堺 提交于 2020-01-01 11:40:04

问题


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 -->

回答1:


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);


来源:https://stackoverflow.com/questions/12079099/actionbarsherlock-background-does-not-repeat-on-pre-ics-versions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!