gpt4 book ai didi

android - 如何在 android 中单击 TextView 超链接打开 Google 页面?

转载 作者:行者123 更新时间:2023-11-30 03:29:18 25 4
gpt4 key购买 nike

How to open a Google home page on click on hyperlink text view in android am trying out with following code but on click on the hyperlink it just changing to normal text how to resolve it

代码如下:

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>

布局测试.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" />

最佳答案

您好,我通过在 java 类中添加这一小段代码以及布局 xml 文件中的少量更改得到了解决方案

instruction = (TextView) findViewById(R.id.example);

instruction.setText(Html
.fromHtml("<b> To open google console </b> "
+ "<a href=\"https://code.google.com/apis/console\">Click here</a> "));
instruction.setMovementMethod(LinkMovementMethod.getInstance());

layout_test.xml

 <TextView
android:id="@+id/example"
android:layout_width="match_parent"
android:layout_height="match_parent" />

关于android - 如何在 android 中单击 TextView 超链接打开 Google 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17749250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com