Android 使用包含可单击HTML链接的字符串设置TextView
我在布局中有一个Android 使用包含可单击HTML链接的字符串设置TextView,android,textview,Android,Textview,我在布局中有一个TextView <TextView android:id="@+id/homepage" android:layout_width="wrap_content" android:layout_height="wrap_content" 结果是请访问www.google.com,但是www.google.com不是可点击的链接。如何使其可点击?(我的意思是单击时在浏览器中打开链接)试试这个 不要忘记在www.之前使用http://,否则您将获得A
TextView
<TextView
android:id="@+id/homepage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
结果是请访问www.google.com,但是www.google.com不是可点击的链接。如何使其可点击?(我的意思是单击时在浏览器中打开链接)试试这个
不要忘记在www.
之前使用http://
,否则您将获得ActivityNotFoundException
TextView homepage = (TextView)findViewById(R.id.homepage);
homepage.setMovementMethod(LinkMovementMethod.getInstance());
homepage.setText(Html.fromHtml("<font color='#696969'> please go to <a href=\""+"http://www.google.com"+"\">"+"http://www.google.com"+"</a></font>"));
TextView主页=(TextView)findViewById(R.id.homepage);
setMovementMethod(LinkMovementMethod.getInstance());
setText(Html.fromHtml(“请转到”);
下面的代码适合我:-
<TextView
android:id="@+id/txt_post_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:textSize="16sp" />
此博客中介绍了所有执行此操作的代码。。检查一下
试试这段代码,它对我有用。为此,请使用可单击的范围。
TextView homepage = (TextView)findViewById(R.id.homepage);
homepage.setMovementMethod(LinkMovementMethod.getInstance());
homepage.setText(Html.fromHtml("<font color='#696969'> please go to <a href=\""+"http://www.google.com"+"\">"+"http://www.google.com"+"</a></font>"));
<TextView
android:id="@+id/txt_post_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:textSize="16sp" />
<TextView
android:id="@+id/links"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:autoLink="web"
android:text="www.google.com" />