ActionBarSherlock背景不能在pre ICS版本的重复能在、背景、版本、ActionBarSherlock

2023-09-05 07:35:46 作者:时光斑驳了记忆

我感动我的应用程序的动作条为ActionBarSherlock,我想自定义一个平铺背景的背景。我测试的2真机我的code,一台运行Android 2.1系统和其他运行Android 4.0.4。

下面的code为工作在ICS设备上(背景不重复),但是不能在埃克莱尔酮(背景被拉伸,而不是重复)。我还测试了这款在Android 2.3模拟器和背景不重复了。看来 TILEMODE =重复只工作在ICS。

的themes.xml:

 <样式名称=Theme.Opheodrys.Base父=Theme.Sherlock.Light>
    <项目名称=机器人:actionBarStyle> @风格/ Opheodrys.Widget.ActionBar< /项目>
    <项目名称=actionBarStyle> @风格/ Opheodrys.Widget.ActionBar< /项目>
< /风格>

<样式名称=Opheodrys.Widget.ActionBar父=Widget.Sherlock.Light.ActionBar>
    <项目名称=机器人:背景> @可绘制/ ab_background_pattern< /项目>
    <项目名称=背景> @可绘制/ ab_background_pattern< /项目>
< /风格>
 

ab_background_pattern.xml:

 < XML版本=1.0编码=UTF-8&GT?;
<位图的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:SRC =@可绘制/ ab_background_tile
    机器人:TILEMODE =回头客
    TILEMODE =重复/> <! - 我把这个添加以防万一,但它似乎并不需要 - >
 

解决方案 国寿重疾险政保合作版A款能不能买 好不好 具体保障如何 值得入手吗

这是 Android的错误#15340 而不是ActionBarSherlock错误

您可以用类似的东西来解决这个问题:

  BitmapDrawable BG =(BitmapDrawable)getResources()getDrawable(R.drawable.bg_striped)。
bg.setTileModeXY(TileMode.REPEAT,TileMode.REPEAT);
getSupportActionBar()setBackgroundDrawable(BG)。
 

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

解决方案

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