我试图通过使用Spannable
String来更改我的字符串,使其中间带有数字的徽章。我可以通过设置BackGroundColorSpan突出显示适当的字母/数字,但是需要一些帮助使其更加漂亮。我希望圆角周围有一些填充物。
由于资源与应用程序的交互方式,我确实需要将资源保留为TextView。
有什么想法如何针对我的特定情况使用ReplacementSpan?
这是我的代码段:
if (menuItem.getMenuItemType() == SlidingMenuItem.MenuItemType.NOTIFICATIONS) {
myMenuRow.setTypeface(null, Typeface.NORMAL);
myMenuRow.setTextColor(getContext().getResources().getColor(R.color.BLACK));
myMenuRow.setActivated(false);
SpannableString spannablecontent = new SpannableString(myMenuRow.getText());
spannablecontent.setSpan(new BackgroundColorSpan(Color.argb(150,0,0,0)), 18, myMenuRow.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
myMenuRow.setText(spannablecontent);