我有一个简单的 按钮
:
<Button
android:id="@+id/test"
android:textColor="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
尝试通过以下方式更改文本属性:
SpannableString span = new SpannableString(text);
span.setSpan(new AbsoluteSizeSpan(8, true), 5, 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
testButton.setText(span);
它可以在Android 4.3上运行,但不能在5.0上运行。
有趣的是,当我将实现从Button
更改为TextView
时,它在5.0上可以正常工作。似乎是Lollipop中Button
的问题。
AbsoluteSizeSpan
,那么它可能会丢失,因为Android 5.0似乎更想控制标题,例如强制将它们全部转换为大写字母。 - CommonsWareAbsoluteSizeSpan
继续工作。 - CommonsWare