android - 如何更改按钮的文本颜色?

标签 android android-layout android-button

如何更改按钮的文本颜色?

最佳答案

试试这个:

button.setTextColor(getApplication().getResources().getColor(R.color.red)); //TAKE DEFAULT COLOR

button.setTextColor(0xff0000); //SET CUSTOM COLOR 

button.setTextColor(Color.parseColor("#ff0000")); 

在 xml 中:

<Button android:id="@+id/mybtn" 
        android:text="text textx "  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"  
        android:textStyle="bold" 
        android:textColor="#ff0000" />  <-- SET TEXT COLOR HERE -->

关于android - 如何更改按钮的文本颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11176365/

相关文章:

java - 滚动 ListView 时丢失项目背景颜色

java - 使用 OpenCV 在 Android 上进行数字识别的训练数据

android - MaterialToggleButton 的选定颜色为纯色

Android 如何将标题与 ListView 项目对齐

android - Android ListView 中的按钮不响应点击

android - Material 按钮背景渐变

java - Android - 在 View 中显示带有自定义文本的 fragment

android - onClickListener ListView

Android Button drawableEnd Style Item

Android:调试触摸、焦点等下的 UI 元素