Reputation: 629
How to give color to string: Example:
String str="Hello Android";
How to give color to the above string?
Also how to give red color to string "cancel" the following :
final String[] items = { "Switch Off", "Timer Settings","Cancel"};
Upvotes: 0
Views: 478
Reputation: 789
Instead of string use TextView
and change the background of it e.g
TextView tv;
tv.setText("yourText");
tv.setTextColor(Color.CYAN);
Upvotes: 0
Reputation: 5619
final CharSequence[] items = {
"Switch Off",
"Timer Settings",
Html.fromHtml("<font color=\"red\">Cancel</font>"),
};
Upvotes: 2
Reputation: 3926
Use spannable class to do this:
Spannable WordtoSpan = new SpannableString(myString);
WordtoSpan.setSpan(new ForegroundColorSpan(Color.RED), 0, myString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Upvotes: 3