Android 如何在任何地方应用文本颜色
我不想把所有的文字颜色都改成绿色。除了将android:textColor复制粘贴到xml文件中的每个editText/TextView之外,还有其他方法可以做到这一点吗?或者可能将默认颜色更改为绿色而不是黑色。任何帮助,谢谢:D您可以创建样式并在任何地方应用它,或者您可以扩展android TextView,它将以绿色作为标准颜色最简单的方法是将此添加到应用程序的主题定义中:Android 如何在任何地方应用文本颜色,android,colors,Android,Colors,我不想把所有的文字颜色都改成绿色。除了将android:textColor复制粘贴到xml文件中的每个editText/TextView之外,还有其他方法可以做到这一点吗?或者可能将默认颜色更改为绿色而不是黑色。任何帮助,谢谢:D您可以创建样式并在任何地方应用它,或者您可以扩展android TextView,它将以绿色作为标准颜色最简单的方法是将此添加到应用程序的主题定义中: <item name="android:textColorPrimary">#ff00ff00</i
<item name="android:textColorPrimary">#ff00ff00</item>
#ff00ff00
您可以提供文字值或颜色资源(
@color/foo
)是的,有一种非常简单的方法可以实现这一点
在AndroidManifext.xml中,将此行放在应用程序标记中
android:theme="@style/CustomTheme"
并在value文件夹下的style.xml中定义CustomTheme
<style name="CustomTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:textColor">@color/app_black</item>
</style>
@颜色/应用程序\黑色
您可以在styles.xml中创建这样的自定义样式
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:capitalize">characters</item>
<item name="android:typeface">monospace</item>
<item name="android:textStyle">bold|italic</item>
<item name="android:shadowDx">1.2</item>
<item name="android:shadowDy">1.2</item>
<item name="android:shadowRadius">2</item>
<item name="android:textColor">#F57025</item>
<item name="android:gravity">center</item>
<item name="android:layout_margin">3dp</item>
<item name="android:textSize">5pt</item>
<item name="android:shadowColor">#000000</item>
</style>
<!-- Custom Style defined for the buttons. -->
<style name="CustomButtonStyle">
<item name="android:textColor">@android:color/darker_gray</item>
<item name="android:textSize">30sp</item>
<item name="android:layout_width">100dp</item>
<item name="android:layout_height">38dp</item>
</style>
人物
单空间
粗体|斜体
1.2
1.2
2.
#F57025
居中
3dp
5吨
#000000
@android:颜色/深灰色
30便士
100dp
38dp
在清单中定义该样式
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
谢谢,伙计,它起作用了:D但我如何在editText和按钮上的文本上应用相同的颜色?对于按钮,您可以在主题中使用@style/MyButtonStyle
。在style.xml中定义MyButtonStyle(使用textColor)。我们的想法是,这可以通过使用样式/主题来实现