AndroidでハイパーリンクテキストビューをクリックしてGoogleホームページを開く方法は、次のコードで試していますが、ハイパーリンクをクリックすると、通常のテキストに変更されるだけです。それを解決する方法
コードは次のとおりです。
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" />