简体   繁体   中英

Change color in a string array

我现在有1个带有某些文本的listview,我想更改粗体的“俱乐部”或灰色的“成本:1 GP,损坏:1D6”?

String[] ad = {"Simple Melee Weapons", "Club\nCost: 1 GP, Damage: 1D6"}
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.

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