Reputation: 171
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
Here is the code:
MainActivity.java (in 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());
}
});
strings.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" />
Upvotes: 1
Views: 1410
Reputation: 171
Hi i got solution by using adding this small piece of code in java class and also little changes in layout xml file
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" />
Upvotes: 1