按钮文本格式不适用于较旧的 API
Button Text Formats Don't Work On Older API's
我正在尝试使用如下所示的文本设置按钮:
.99 .99
但是,在一些较旧的设备上,格式根本不会出现。我已经尝试 Html.fromHtml
,并且自己构建了 SpannableString
,none 成功了!
无论出于何种原因,将 Button
更改为 TextView
似乎可以解决问题![=16=]
编辑:使用 Button
工作得很好,但是对于 26 之前的 API,您需要将 textAllCaps
设置为 false
. 感谢@Mike M. 的解释!
以下代码现在有效:
SpannableString spannableString = new SpannableString(oldBuyPrice + newBuyPrice);
spannableString.setSpan(new StyleSpan(Typeface.ITALIC), 0, oldBuyPrice.length(), 0);
spannableString.setSpan(new StrikethroughSpan(), 0, oldBuyPrice.length(), 0);
buyButtonTextView.setText(spannableString);
我正在尝试使用如下所示的文本设置按钮:
.99.99
但是,在一些较旧的设备上,格式根本不会出现。我已经尝试 Html.fromHtml
,并且自己构建了 SpannableString
,none 成功了!
无论出于何种原因,将 Button
更改为 TextView
似乎可以解决问题![=16=]
编辑:使用 Button
工作得很好,但是对于 26 之前的 API,您需要将 textAllCaps
设置为 false
. 感谢@Mike M. 的解释!
以下代码现在有效:
SpannableString spannableString = new SpannableString(oldBuyPrice + newBuyPrice);
spannableString.setSpan(new StyleSpan(Typeface.ITALIC), 0, oldBuyPrice.length(), 0);
spannableString.setSpan(new StrikethroughSpan(), 0, oldBuyPrice.length(), 0);
buyButtonTextView.setText(spannableString);