Essayez ceci.
Way 1. utiliser setMovementMethod
et Html.fromHtml
Je n'ai pas défini maxLines
et ellipsize
. C'est un bon travail.
Dans votre code XML
<TextView
android:id="@+id/tv_html"
android:ellipsize="end"
android:maxLines="5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Alors Dans votre code 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
Way 2. utiliser android:autoLink="all"
dans le code XML
<TextView
android:id="@+id/tv_html"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"/>
Puis dans votre code java.
TextView tv_html = (TextView) findViewById(R.id.tv_html);
tv_html.setText("google: https://www.google.com.hk"));
Way 3. utilisez SpannableString
dans le code.
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());
Modifier
Il peut faire défiler mais pas montrer l'...
.
Vous pouvez ajouter
android:scrollbars="vertical"
Pourriez-vous vérifier ma réponse? – KeLiuyue