0

When i try to change background color of radio button text programatically like this:

rb.setBackgroundResource(R.drawable.mycustombackground);

The background covers both the button and the text.
I only want to change the background color of the text part (not the radio button).

How to achieve that?

4

1 回答 1

1

好的,让我们看看它是否有效:

Spannable span = new SpannableStringBuilder(rb.getText().toString());
span.setSpan(new BackgroundColorSpan(Color.RED), 0, rb.getText().toString().length(), SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
rb.setText(span);

将 Color.RED 替换为您想要的任何颜色。不要忘记,如果需要,您必须从资源中获取它。我认为它不适用于可绘制对象。

于 2015-03-09T15:12:50.353 回答