fil*_*pst 5 android hyperlink textview
我有一个应用程序,其中包含在 strings.xml 中的大量文本。该文本的一部分是必须可点击的超链接。
现在,当我从布局文件中将该文本插入到 TextView 中时,它可以工作,但是当我尝试使用 tv.settext(getStrings...) 将相同的文本插入到同一个 TextView 中时,它将不起作用。
这是代码:
字符串.xml:
<string name="some_text">
For you to see the article, you need to click <a href='http://www.google.com'>this link</a>
\n\n
after that etc...
</string>
Run Code Online (Sandbox Code Playgroud)
活动:
TextView txt = findViewById(R.id.link_tv);
txt.setMovementMethod(LinkMovementMethod.getInstance());
txt.setText(getString(R.string.some_text));
Run Code Online (Sandbox Code Playgroud)
活动_main.xml:
<TextView
android:id="@+id/link_tv"
android:textColor="@color/privacy_policy_link_text_color"
android:paddingLeft="@dimen/_5sdp"
android:paddingRight="@dimen/_5sdp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
测试前检查以下点
http://
或开头https://
<string name="some_text"><![CDATA[PLACE_YOUR_HTML_STRING_HERE]]></string>
)manifest.xml
文件中添加了 Internet 权限<uses-permission android:name="android.permission.INTERNET"/>
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
textView.setText(Html.fromHtml(getString(R.string.html_string), Html.FROM_HTML_MODE_COMPACT));
} else {
textView.setText(Html.fromHtml(getString(R.string.html_string)));
}
Linkify.addLinks(textView, Linkify.ALL);
textView.setMovementMethod(LinkMovementMethod.getInstance());
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1304 次 |
最近记录: |