所以这张图片基本上显示了我想要做的事情:
我想在已经有文字的按钮上添加静态文本(橙色A)。但我不知道怎么做。
答案 0 :(得分:0)
您可以尝试Html.fromHTML(htmlString)。类似的东西:
myTextButton.setText(Html.fromHtml("<font color='#FFA500'>A: </font> whatever text you need here"));
答案 1 :(得分:0)
转到@blackbelt
Spannable wordtoSpan = new SpannableString("A: Text");
wordtoSpan.setSpan(new ForegroundColorSpan(Color.ORANGE), 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
button.setText(wordtoSpan);
其中button
是您的Button
对象..
,其中
.setSpan(what,start,end,flag);
,其中
什么 有ForegroundColorSpan或StyleSpan或UnderlineSpan对象。 ForegroundColorSpan为color选择一个整数参数,StyleSpan也为style设置一个参数,但UnderlineSpan不接受任何参数。
start 有字符串的起点,您可以在哪里开始样式颜色的字符串索引。
结束 有字符串的结束点,你会在哪里结束样式颜色的字符串索引。
标志 可以有1或0。
您还可以将字体大小更改为字符串的一部分.. refer this link for ref