简体   繁体   中英

android how to set hyperlink in textview

I want to set hyperlink with textview in android so anyone can help me on it. My code is given below.

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Authentication failed. Please visit www.google.com"
    />

Try this. Add ID field in the xml and then do so.

TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "Authentication Failed . Please visit <a href='http://.www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM