Android TextView:如果来自HTML和android的setText,则不显示文本:singleLine =“true”

时间:2015-06-03 21:41:44

标签: android html textview

我正在将文本设置为TextView调用

tv.setText(Html.fromHtml("<a href=\"" + link + "\">" + text + "</a>"));

此文字是一个网站链接。

这个工作正常,直到我自己剪切文本。 现在我已经设置了:

android:singleLine="true"
android:ellipsize="end"

到TextView,文本不再可见。

这是一个已知问题还是什么?

编辑:

为了让其他人更好地理解这个问题,我会详细解释发生了什么:

这是我的TextView:

    <TextView
        android:id="@+id/txtEventRecipient"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:enabled="true"
        android:focusable="false"
        android:gravity="center"
        android:linksClickable="true"
        android:padding="5dp"
        android:textColor="@drawable/elv_title_1_selector"
        android:textSize="@dimen/small_text_size"
        android:textStyle="bold"
        android:typeface="normal" />

这是我将文本设置为链接的代码:

TextView tv = (TextView) convertView.findViewById(R.id.txtEventRecipient); 
String userName = "<a user name got from somewhere>";

// here I was cutting the userName as it's length must fit 
if (userName.length() > 16)
    userName = userName.substring(0, 15) + "…";

// here I set the link to the user
tv.setText(Html.fromHtml("<a href=\"" + link + "\">" + userName + "</a>"));
tv.setMovementMethod(LinkMovementMethod.getInstance());

这是有效的,但是以最大长度固定16,所以我决定用“singleLine”让它变得更有活力。

singleLine="true"导致问题没有将文字显示为HTML链接。

1 个答案:

答案 0 :(得分:1)

android:singleLine已经或多或少地被弃用了一段时间。它很少有效。 android:maxLines="1"现在比较典型。