按钮的setText与Android的5.0棒棒糖Spannable忽略了最低工作 [英] Button setText with Spannable dosen't work for Android 5.0 Lollipop

查看:182
本文介绍了按钮的setText与Android的5.0棒棒糖Spannable忽略了最低工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的按钮

<Button
    android:id="@+id/test"
    android:textColor="@color/white"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

和尝试改变text属性是:​​

and try change text property by:

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却没有。

It works with Android 4.3, but doesn't with 5.0.

有趣的是,当我改变实现从按钮的TextView 它的工作罚款5.0。似乎有什么东西在棒棒堂按钮

The interesting thing is when I change implementation from Button to TextView it work fine for 5.0. Seems to be something with Button in Lollipop.

推荐答案

在默认情况下,材质按钮样式来显示全大写文字。然而,在一个错误的 AllCapsTransformationMethod 用于资本化,导致它放弃 Spannable 数据。

By default, Material buttons are styled to show text in all-caps. However, there is a bug in the AllCapsTransformationMethod used for capitalization that causes it to discard Spannable data.

您可以覆盖默认的按钮样式,并通过指定安卓禁用所有大写:textAllCaps =假按钮

You can override the default button styling and disable all-caps by specifying android:textAllCaps="false" on your Button.

<Button
    ...
    android:textAllCaps="false" />

这篇关于按钮的setText与Android的5.0棒棒糖Spannable忽略了最低工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆