setting textColor in TextView in layout/main.xml main layout file not referencing colors.xml file. (It wants a #RRGGBB instead of @color/text_color)

前端 未结 4 1622
一向
一向 2020-12-14 00:10

I\'m trying to set some general colors for a program I\'m writing. I created a colors.xml file and am trying to directly reference the colors from the layout.xml file. I bel

相关标签:
4条回答
  • 2020-12-14 00:28

    You should write textcolor in xml as

    android:textColor="@color/text_color"
    

    or

    android:textColor="#FFFFFF"
    
    0 讨论(0)
  • 2020-12-14 00:33

    After experimenting on that case: android:textColor="@colors/text_color" is wrong since @color is not filename dependant. You can name your resource file foobar.xml, it doesn't matter but if you have defined some colors in it you can access them using @color/some_color.

    Update:

    file location: res/values/colors.xml The filename is arbitrary. The element's name will be used as the resource ID. (Source)

    0 讨论(0)
  • 2020-12-14 00:35

    You have a typo in your xml; it should be:

    android:textColor="@color/text_color"
    

    that's "@color" without the 's'.

    0 讨论(0)
  • 2020-12-14 00:41

    A variation using just standard color code:

    android:textColor="#ff0000"
    
    0 讨论(0)
提交回复
热议问题