开发者

Android: How to create custom text for website link?

开发者 https://www.devze.com 2023-03-14 10:52 出处:网络
Es开发者_运维问答sentially I want to make something like http://stackoverflow.com appear as \"Stack\" in a checkedtextview and be a link. How can I do that?TextView can display dumbed-down tagsoup HTM

Es开发者_运维问答sentially I want to make something like http://stackoverflow.com appear as "Stack" in a checkedtextview and be a link. How can I do that?


TextView can display dumbed-down tagsoup HTML, including <a href=""/> tags. If that's in strings.xml, and you set the text using android:text, it should just happen automatically. Otherwise, you'll need to pass the html string to Html.fromHtml(). Example:

CheckedTextView ctv = (CheckedTextView) findViewById(R.id.whatever);
ctv.setText(Html.fromHtml("<a href=\"http://stackoverflow.com\">Stack</a>"));

Your layout should also set android:linksClickable="true" on the CheckedTextView

0

精彩评论

暂无评论...
验证码 换一张
取 消