我想在我的AppTheme中设置默认文本颜色,应该是黑色(而不是默认的Material Design深灰色)。文本颜色应该通过在UI元素上设置android:textAppearance属性的自定义样式来覆盖(例如TextView)。
这是我的当前设置:
我在项目中使用了AppCompat库:
compile 'com.android.support:appcompat-v7:22.2.0'
我定义了以下主题:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:textColorPrimary">@color/black</item> <!-- All TextViews should have this color as default text color -->
</style>
这个是在AndroidManifest.xml中设置的:
<application
android:name=".core.BaseApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
此外,我定义了一些样式来改变某些TextView的textAppearance:
<style name="App.Heading" parent="android:TextAppearance.Widget.TextView">
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/red</item>
</style>
<style name="App.Heading.Highlighted" parent="android:TextAppearance.Widget.TextView">
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/blue</item>
</style>
现在我有一个包含一些TextView的xml-layout。其中一些应该具有默认的textAppearance(实际上是黑色文本颜色,如我的主题中定义的android:textColorPrimary)。有些应该应用于我定义的样式中的自定义textappearance:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="CUSTOM: App.Heading"
android:textAppearance="@style/App.Heading" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="CUSTOM: App.Heading.Highlighted"
android:textAppearance="@style/App.Heading.Highlighted" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Normal Textview with no style"/>
前两个TextView应用了我定义的textAppearance,这很好。但是最后一个TextView具有深灰色的文本颜色(Material Design默认颜色?),而不是黑色的。如果我设置属性:
<item name="android:textColor">@color/black</item>
在我的App主题中,所有TextView都有黑色文本颜色。在我的样式中定义的文本颜色(例如App.Heading)不再被识别。
因此,我的问题是:如何为我的TextView设置默认文本颜色,可以通过设置textAppearance进行覆盖?