我正在尝试通过使用Spannable String来更改我的字符串以使用中间的数字制作徽章.我可以通过设置BackGroundColorSpan突出显示相应的字母/数字,但需要帮助使它更漂亮.我希望有圆角,整个形状周围有一点填充.
这篇文章非常接近我正在尝试做的事情:Android SpannableString在文本部分后面设置背景
由于它与我的应用程序交互的方式,我真的需要将资源保留为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);
Run Code Online (Sandbox Code Playgroud)