【问题标题】:Theme and style properties for background image背景图像的主题和样式属性
【发布时间】:2011-11-02 17:47:51
【问题描述】:
我阅读了文档,上面写着“样式可以指定诸如高度、填充、字体颜色、字体大小、背景颜色等属性”,现在我的问题是什么是“更多”。这是否意味着我可以为 android:src 定义不同的属性?
就是这样的
<item name="android:src">@drawable/attachment1</item>
我尝试了背景属性,它工作正常
<item name="android:background">#55FFFFFF</item>
但不是 src 属性 :-(.
我做错了什么?
【问题讨论】:
标签:
android
image
themes
styles
【解决方案1】:
在我的测试中,根据这篇文章 (How to change a TextView's style at runtime),在样式中设置背景图像不起作用。
如果您以编程方式设置样式,请在您的 java 类中尝试这样的操作:
countField.setTextAppearance(getContext(),R.style.theme_id);
countField.setBackgroundResource(R.drawable.attachment1);
如果您在布局中设置样式,或者类似这样:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello world"
android:layout_gravity="center"
android:textAppearance="@style/MVTheme.TextAppearance.CalendarMissedCount"
android:background="@drawable/attachment1 />
【解决方案2】:
试试:
<item name="android:background">@drawable/attachment1</item>
【解决方案3】:
试试这个:
<item name="android:windowBackground">@drawable/imageone</item>
【解决方案4】:
您不能直接使用可绘制对象。在 res/drawable 中创建一个 xml 文件。在您的 style.xml 中引用它。
res/drawable/attach.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/attachment1"
/>
res/values/styles.xml
<item name="android:src">@drawable/attach</item>
我还没有建立 ^^ 但这是一般的想法。