它可能看起来很简单,但我很困惑这个问题,我想在我的应用程序中添加超链接例如:www.example of address with spaces.html
但是当我把url放在代码中时它看起来像这样
这是我的代码
<TextView
android:id="@+id/link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:linksClickable="true"
android:autoLink="web"
android:layout_marginLeft="10dp"
android:textColor="@color/white"
android:text="http://www.example of an address with spaces.html" />
答案 0 :(得分:2)
尝试以下代码
tvTermsOfUse.setText(Html.fromHtml(getString(R.string.tv_terms_of_use_html)));
Linkify.addLinks(tvTermsOfUse, Linkify.ALL);
tvTermsOfUse.setMovementMethod(LinkMovementMethod.getInstance())
<TextView
android:id="@+id/tv_terms_of_use"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textAlignment="gravity"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="15sp"
/>
<string name="tv_terms_of_use_html"><![CDATA[This is link to <a href="http://google.com/">Google with spaces</a>.]]></string>
答案 1 :(得分:1)
如何做到这一点programmatically
简单易用
从android:text="http://www.example of an address with spaces.html"
xml code
将以下内容添加到您的java code
TextView txt = (TextView) findViewById(R.id.link);
txt.setText(Html.fromHtml("<a href=www.google.com>link with space</a>"));
答案 2 :(得分:1)
尝试下面的内容,
TextView mTextView1 = (TextView) findViewById(R.id.my_text_view_html);
String text =
"Visit <a href=\"http://www.google.com/\">Google home page</a>";
mTextView1.setText(Html.fromHtml(text));
mTextView1.setMovementMethod(LinkMovementMethod.getInstance());
答案 3 :(得分:1)
尝试XML CDATA
<string name="demoStr"><Data><![CDATA[ <b>ABC</b> ]]> </Data></string>