【问题标题】:Set colour to text in Android activity?在Android活动中将颜色设置为文本?
【发布时间】:2011-11-18 01:25:11
【问题描述】:

我想在我的应用程序中设置一个红色文本,但我不知道如何。

请提供参考资料。谢谢。

【问题讨论】:

    标签: android text colors


    【解决方案1】:

    如果你想在 XML 布局中设置,那么使用:

    <TextView 
     ...
     ...
     android:textColor="#FF0000" >
     </TextView>
    

    如果您想以编程方式设置,请使用:

    textview.setTextColor(Color.RED);
    //textview must be defined in your class 
    

    【讨论】:

      【解决方案2】:

      阅读TextView 的文档,特别是textColor

      【讨论】:

        【解决方案3】:

        在您想要将颜色更改为红色的xml 中使用以下内容,并使用其他颜色的十六进制代码您可以更改为任何其他颜色。这是将颜色设置为红色的示例:

        android:textColor="#FF0000" 
        

        【讨论】:

          【解决方案4】:

          在你的布局中使用它:

          <TextView>
            ....
            textColor="red"
            ....
          </TextView>
          

          【讨论】:

            【解决方案5】:

            创建一个使用Android Theme 作为父级的custom style resource,然后覆盖Android theme.xml 中定义的文本颜色。在您的 AndroidManifest.xml's application tag 中引用此新样式。

            【讨论】:

              猜你喜欢
              • 2012-09-13
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2012-11-12
              • 2012-02-24
              • 2023-03-11
              • 2021-11-29
              • 1970-01-01
              相关资源
              最近更新 更多