我创建了一个对话框来在 android 中显示消息。它基本上在 ScrollView 中包含一个 TextView ,如下所示
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/about_msg"
android:text="@string/about_msg"
android:autoLink="web"
android:padding="10dip"
style="@style/DialogTextSmall" />
</ScrollView>
如您所见,我已将样式应用于 TextView,样式如下所示
<style name="DialogTextSmall">
<item name="android:textSize">@dimen/text_size_small</item>
</style>
应用主题设置是这样的
<style name="AppTheme" parent="android:Theme.Light">
问题:
在 ICS api-15 上,它在 TextView 的白色背景上显示精细的黑色文本。
问题是当我在 Froyo 中显示对话框时,即使它似乎占用了空间,文本似乎也没有显示 - 我的猜测是文本的颜色与背景相同(灰黑色)
我知道我可以通过硬编码黑色背景和白色文本来快速修复,但是是否不可能为 TextView 的文本颜色和背景显示平台的默认颜色,而无需我对它们进行硬编码?
最佳答案
您可以继承父样式,然后仅更改您想要更改的值。尝试将您的 XML 更改为:
<style name="DialogTextSmall" parent="@android:style/Widget.TextView>
<item name="android:textSize">@dimen/text_size_small</item>
</style>
您可以继承的样式列表可以在Github上的AOSP源中找到here .
EIDT:
默认情况下, TextView 具有黑色文本和透明背景,因此如果 TextView 后面的背景(同样是透明的)是黑色,则需要设置其中之一。
关于android - 对话框中的TextView样式,在froyo中看不到文本,但在ics中可以看到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13853298/