动作条的背景图片背景图片、动作

2023-09-12 01:34:10 作者:别拿本菇凉跟淑女比

我继承了全息光的主题和个性化的动作条,具有以下背景:

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

styles.xml含量

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>

actionbar_background.xml含量

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

而不是被重复时,图像被拉伸,为什么android的任何想法:?TILEMODE =重复不适用

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

在此先感谢

推荐答案

好了,感谢罗曼盖伊上#的android-dev的IRC频道,它是在蜂巢中的已知错误/安卓3.0将被固定在下一版本中。自那以后,唯一的办法就是从code做到这一点,它的工作原理: - )

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