我有maxLines:5
和ellipsize:end
施加TextView
,我還使用setMovementMethod(LinkMovementMethod.getInstance())
在TextView
生成鏈接點擊(HTML內容)。的TextView MAXLINES,運動方法和ellipsize
上述所有組合都會禁用正被截斷的文本和要附加的'...'後綴。
任何想法出了什麼問題,以及如何解決它?
沒有設置移動方法,一切都按預期工作。
我有maxLines:5
和ellipsize:end
施加TextView
,我還使用setMovementMethod(LinkMovementMethod.getInstance())
在TextView
生成鏈接點擊(HTML內容)。的TextView MAXLINES,運動方法和ellipsize
上述所有組合都會禁用正被截斷的文本和要附加的'...'後綴。
任何想法出了什麼問題,以及如何解決它?
沒有設置移動方法,一切都按預期工作。
<TextView
android:id="@+id/html"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:ellipsize="end"/>
//inside your activity
public class A extends AppCompatActivity{
TextView html = (TextView) view.findViewById(R.id.html);
html.setText(Html.fromHtml("this is an example <a href=\"www.google.com\">google</a> link to google"));
html.setMovementMethod(LinkMovementMethod.getInstance());
.
.
.
}
如果您未設置maxLines,則代碼 – aviran
試試這個。
方式1。使用setMovementMethod
和Html.fromHtml
我沒有設置maxLines
和ellipsize
。它工作正常。
在XML代碼
<TextView
android:id="@+id/tv_html"
android:ellipsize="end"
android:maxLines="5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
然後在Java代碼中
TextView tv_html = (TextView) findViewById(R.id.tv_html);
tv_html.setText(Html.fromHtml("google:" + "<a href='https://www.google.com.hk'>link to it</a> "));
tv_html.setMovementMethod(LinkMovementMethod.getInstance());// make it active
路2。在XML代碼中使用android:autoLink="all"
<TextView
android:id="@+id/tv_html"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"/>
然後在您的java代碼中。
TextView tv_html = (TextView) findViewById(R.id.tv_html);
tv_html.setText("google: https://www.google.com.hk"));
路3。在代碼中使用SpannableString
。
TextView tv_html = (TextView) findViewById(R.id.tv_html);
SpannableString ss = new SpannableString("google: link to google");
ss.setSpan(new URLSpan("https://www.google.com.hk"), 8, 22, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tv_html.setText(ss);
tv_html .setMovementMethod(LinkMovementMethod.getInstance());
編輯
它可以滾動,但不能顯示...
。
您可以添加
android:scrollbars="vertical"
試試這個代碼。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="20dp"
android:id="@+id/txtTitle"
android:text="" />
String message="<font color='gray'>"+"YOUR CONTENT"+ "<br>" +"<font color='cyan'>"+"<font size='5'>"+" "+"</font>";
txtTitle.setBackgroundColor(Color.TRANSPARENT);
txtTitle.setText(message);
你能檢查我的答案嗎? – KeLiuyue