Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用包含可单击HTML链接的字符串设置TextView_Android_Textview - Fatal编程技术网

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" />