【发布时间】:2013-07-19 14:55:06
【问题描述】:
如何在android中点击超链接文本视图打开谷歌主页我正在尝试使用以下代码但点击超链接它只是变成普通文本如何解决它
代码如下:
MainActivity.java(在 onCreate() 中)
instruction = (TextView) findViewById(R.id.example);
instruction.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
instruction.setText(Html.fromHtml(getString(R.string.Google_Instructions)));
Linkify.addLinks(instruction, Linkify.ALL);
instruction.setMovementMethod(LinkMovementMethod.getInstance());
}
});
字符串.xml
<string name="Google_Instructions">opens <a href="https://www.google.co.in">Google</a> page </string>
layout_test.xml
<TextView
android:id="@+id/example"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:clickable="true"
android:text="@string/Google_Instructions"
android:autoLink="web"
android:textSize="16sp" />
【问题讨论】:
-
你想在浏览器中打开它吗?
-
stackoverflow.com/questions/7570239/…。搜索,这样你就会有很多类似的帖子
-
您是要在您的应用程序中嵌入网络浏览器还是在您的设备上启动默认浏览器。每个所需的代码显然差异很大
-
@MikeBaglioJr。我想在设备中启动默认浏览器
标签: android hyperlink textview