简体   繁体   中英

How to set color in Java code (Android)

My code,

if (position == 1) {
    return new DummyItem(String.valueOf(position), "  ABOUT "+"ME", String.valueOf(position));
} else if (position == 2) {
    return new DummyItem(String.valueOf(position), "  ABOUT "+"Office", String.valueOf(position));
}

Here in first case return value is "ABOUT ME". So I want to set pink color to "ABOUT ME". How to set color in Java code?

ABOUT ME text field is works like clickable field and when I click on "ABOUT ME" it will call aboutme.XML (xml contain just text/data).

For which Object you would like to set a Color? If you like to set the TextColor of an TextView you could try this: How to set the text color of TextView in code?

if you are trying this out in android's text view. use this as android M requires this. textView.setTextColor(ContextCompat.getColor(context, R.color.your_color));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM