Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ActionBar背景图像_Android_Android 3.0 Honeycomb_Android Actionbar - Fatal编程技术网

Android ActionBar背景图像

Android ActionBar背景图像,android,android-3.0-honeycomb,android-actionbar,Android,Android 3.0 Honeycomb,Android Actionbar,我继承了Holo Light主题,并用以下内容定制了ActionBar的背景: styles.xml的内容 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="ActionBar" parent="@android:style/Widget.Holo.ActionBar"> <item name="android:background">@drawable/actionba

我继承了Holo Light主题,并用以下内容定制了ActionBar的背景:

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的内容

<?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=repeat不被应用吗


提前感谢

好的,感谢android开发IRC频道上的Romain Guy,这是蜂巢/android 3.0上的一个已知错误,将在下一版本中修复。从那时起,唯一的解决方案就是从代码开始,它可以工作:-

 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);
上面的代码为操作栏设置背景图像。
希望有帮助。

你可以很容易地做这件事。如果要更改操作栏背景图像,请将此代码放在res/styles.xml文件中

 <style name="Theme.MyAppTheme" parent="@android:style/Theme.Holo">
        <item name="android:actionBarStyle">@style/Theme.MyAppTheme.ActionBar</item>
    </style>

    <style name="Theme.MyAppTheme.ActionBar" parent="@android:style/Widget.Holo.ActionBar">
        <item name="android:background">@drawable/top_black_bg</item>
    </style>
为此,您必须从drawable文件夹中选择一个图像。在这里,我选择了一个图像tp_black_bg.png

之后,不要忘记将此主题声明到您的AndroidManifest.xml文件中

    <application
        .
        .
        .
        android:theme="@style/Theme.MyAppTheme" >.............</application>
现在可以重新打开任何XML布局文件,您可以很容易地看到效果。同样,您也可以更改ActionBar的背景色


谢谢。

使用android.support.v7中的getSupportActionBar实现向后兼容性。

请问您是如何从代码中实现的?如何设置为tileMode repeat?当我尝试获取动作时,总是得到空值。我是这样做的:final ActionBar ActionBar=getActionBar;BitmapDrawable后台=新的BitmapDrawable BitmapFactory.decodeResourcegetResources,R.raw.actionbar\u后台;background.setTileModeXandroid.graphics.Shader.TileMode.REPEAT;actionBar.setBackgroundDrawablebackground@嗯,最好在回答中添加评论作为编辑。你应该将答案标记为“解决”,因为它解决了问题。对我来说,如果我在挫折后将InvalidatementUoptions称为“可撤销选项”,而不对问题的类型进行任何假设,那么它是有效的Drawable@rnoway:为什么定义actionBar属性final?定义它最终会如何影响它?对不起,我是Java和Android新手。谢谢,但为什么它不支持下面的版本,如2.2、2.3.3等等
mActionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.navbar));
mActionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.navbar));