0

i have 1 listview with some text now i want change "Club" in bold or "Cost: 1 GP, Damage: 1D6" in gray is possible???

String[] ad = {"Simple Melee Weapons", "Club\nCost: 1 GP, Damage: 1D6"}
2
  • 2
    This is hard to answer without the layout you created for this, but to answer your question is you can either use Spannable or Html Commented Jan 22, 2017 at 0:02
  • 2
    Change color in a string array this is not possible, because a string array is not an object with a visible interface. But you can change the color of a substring in a TextView. Commented Jan 22, 2017 at 0:03

1 Answer 1

1
Spannable span = new SpannableString(ad[1]);        

span.setSpan(new ForegroundColorSpan(Color.GRAY), 0, ad[1].length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

span = new SpannableString(ad[0]);
StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
span .setSpan(boldSpan, 0, ad[0].length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

Try searching a little bit more. Stack has everything, this question has been asked a million times.

Sign up to request clarification or add additional context in comments.

3 Comments

I can use this on text of simple_list_item_1??
Of course. You can use it on any string you want. But, if you want to use it in a listview with a default adapter I am afraid you cannot. You will have to create your own adapter implementation in order to modify the appearance of the list elements as you want. I would suggest you though, to try and use recyclerview instead of a listview. It's ten times better since it implements the ViewHolder pattern on its own and it's pretty straight-forward how to use it. If this answer was correct, please mark it so :).
@LuigiDeSimone if this was the answer to your question, which I think it was, please mark it as correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.