Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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 更改按钮文本颜色-可能的解决方案数量?_Android_Xml_Colors_Styles - Fatal编程技术网

Android 更改按钮文本颜色-可能的解决方案数量?

Android 更改按钮文本颜色-可能的解决方案数量?,android,xml,colors,styles,Android,Xml,Colors,Styles,我刚刚开始学习Android Studio和Android开发。我一直在寻找改变应用程序中所有按钮文本颜色的方法 有人能告诉我有多少种方法可以做到这一点,而不必只使用XML硬编码每个按钮的颜色吗 我使用了下面的代码,但我正在寻找所有可能的方法,看看哪个更容易实现 <style> ... <!-- changes Button text colors --> <item name="android:textAppearanceButton">

我刚刚开始学习Android Studio和Android开发。我一直在寻找改变应用程序中所有按钮文本颜色的方法

有人能告诉我有多少种方法可以做到这一点,而不必只使用XML硬编码每个按钮的颜色吗

我使用了下面的代码,但我正在寻找所有可能的方法,看看哪个更容易实现

<style>
...          
<!-- changes Button text colors -->
<item name="android:textAppearanceButton">@style/Base.TextAppearance.AppCompat.Button.Custom</item>
...
</style>

<style name="Base.TextAppearance.AppCompat.Button.Custom">
<item name="android:textColor">#ffffff</item>
</style>

...          
@style/Base.TextAppearance.AppCompat.Button.Custom
...
#ffffff

您可以在主主题中一次为所有按钮添加样式

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- .... --> 
        <item name="android:button">@style/NormalBtn</item>
    </style>

@样式/标准BTN

您可以使用

Button myButton=(Button)findviewbyd(R.id.btn)

myButton.setTextColor(Color.ORANGE)

希望它有助于

可能重复的