如何在Android应用程序上将超链接放置到网站? [英] How to place hyperlink to a website on android app?

查看:60
本文介绍了如何在Android应用程序上将超链接放置到网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在正在开发的android应用上放置超链接.

I want to place a hyperlink on android app that I am developing.

我尝试过:

main.xml

<TextView 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:text="@string/hyperlink"
android:id="@+id/hyperlink" 
android:autoLink="web"
>
</TextView>

strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">WebLink</string>
<string name="hyperlink">http://google.com</string>
</resources>

但是问题是,链接看起来像这样: http://google.com 我不想要显示实际网址.

But the problem is, the link looks like this: http://google.com and I don't want to show the actual url.

1)如何用单击此处访问Google"之类的文本替换链接,并且该文本与网站url链接?

1) How to replace link by text like "Click Here to visit Google" and the text is linked with the website url ?

2)如何放置电子邮件地址(相同的问题,如何用诸如单击此处发送电子邮件"之类的文本替换该电子邮件地址,并且该文本应与

2) How to place email address (same question, how to replace it with text something like "Click Here to Email" and the text should be linked with email@domain.com)

我也尝试了本教程: http://coderzheaven .com/2011/05/10/textview-with-link-in-android/

但是我收到以下错误消息:

But I am getting following error messages:

Description Resource    Path    Location    Type
http cannot be resolved to a variable   MyLink.java /MyLink/src/com/MyLink  line 21 Java Problem
Syntax error on token "" <br /> <a href="", ? expected after this token MyLink.java /MyLink/src/com/MyLink  line 21 Java Problem
Type mismatch: cannot convert from String to boolean    MyLink.java /MyLink/src/com/MyLink  line 20 Java Problem

推荐答案

使用默认的这是一个示例,以及教程:

这是我的示例代码,我认为这可以解决您的问题:

This is my sample code for you, I think this will solve your problem:

    public class StackOverflowActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // 1) How to replace link by text like "Click Here to visit Google" and
        // the text is linked with the website url ?
        TextView link = (TextView) findViewById(R.id.textView1);
        String linkText = "Visit the <a href='http://stackoverflow.com'>StackOverflow</a> web page.";
        link.setText(Html.fromHtml(linkText));
        link.setMovementMethod(LinkMovementMethod.getInstance());
        // 2) How to place email address
        TextView email = (TextView) findViewById(R.id.textView2);
        String emailText = "Send email: <a href=\"mailto:person@stackoverflow.com\">Click Me!</a>";
        email.setText(Html.fromHtml(emailText));
        email.setMovementMethod(LinkMovementMethod.getInstance());
    }
}

这篇关于如何在Android应用程序上将超链接放置到网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆