ActionBarSherlock 背景在 ICS 之前的版本上不会重复

2023-12-29

我正在将应用程序的 ActionBar 移动到 ActionBarSherlock,并且尝试使用平铺背景自定义背景。我正在 2 台真实设备上测试我的代码,一台运行 Android 2.1,另一台运行 Android 4.0.4。

下面的代码适用于 ICS 设备(背景确实重复),但不适用于 Eclair 设备(背景被拉伸而不是重复)。我还在 Android 2.3 模拟器上测试过这个,背景也不会重复。看来tileMode="repeat"只致力于 ICS。

主题.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 -->

This is 安卓错误 #15340 http://b.android.com/15340而不是 ActionBarSherlock 错误。

您可以使用类似以下内容来修复此问题:

BitmapDrawable bg = (BitmapDrawable)getResources().getDrawable(R.drawable.bg_striped);
bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
getSupportActionBar().setBackgroundDrawable(bg);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ActionBarSherlock 背景在 ICS 之前的版本上不会重复 的相关文章

随机推荐