【问题标题】:AutoLink won't recognize an email as an emailAutoLink 不会将电子邮件识别为电子邮件
【发布时间】:2017-08-14 13:08:15
【问题描述】:

我有一段代码可以识别电子邮件,但没有。我认为这是因为电子邮件地址的“开始”部分(@ 符号之前的部分)只有两个字符。有谁知道如何解决这一问题?我尝试使用android:autoLink="all",但这也没有用。

这是我的电子邮件代码:

<TextView
    android:id="@+id/textView7"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="General Inquiries: \ncontact@opsconsulting.com"
    android:layout_marginTop="18dp"
    app:layout_constraintTop_toBottomOf="@+id/textView4"
    android:layout_marginLeft="24dp"
    app:layout_constraintLeft_toLeftOf="parent"
    android:textAppearance="@style/Body"
    android:autoLink="email"
    android:layout_marginRight="16dp"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintHorizontal_bias="0.0" />

<TextView
    android:id="@+id/textView10"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="Human Resources: \nhr@opsconsulting.com"
    android:textAppearance="@style/Body"
    android:layout_marginTop="18dp"
    app:layout_constraintTop_toBottomOf="@+id/textView7"
    android:layout_marginLeft="0dp"
    app:layout_constraintLeft_toLeftOf="@+id/textView7"
    android:layout_marginRight="16dp"
    app:layout_constraintRight_toRightOf="parent" />

<TextView
    android:id="@+id/textView11"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="Recruiting: \nrecruiting@opsconsulting.com"
    android:layout_marginTop="18dp"
    app:layout_constraintTop_toBottomOf="@+id/textView10"
    android:textAppearance="@style/Body"
    android:autoLink="email"
    android:layout_marginLeft="0dp"
    app:layout_constraintLeft_toLeftOf="@+id/textView10"
    android:layout_marginRight="16dp"
    app:layout_constraintRight_toRightOf="parent" />

<TextView
    android:id="@+id/textView12"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="Legal and Contacts: \nlegal@opsconsulting.com"
    android:layout_marginTop="18dp"
    app:layout_constraintTop_toBottomOf="@+id/textView11"
    android:textAppearance="@style/Body"
    android:autoLink="email"
    android:layout_marginLeft="0dp"
    app:layout_constraintLeft_toLeftOf="@+id/textView11"
    android:layout_marginRight="16dp"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintHorizontal_bias="0.0" />

<TextView
    android:id="@+id/websitegoto"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:text="www.opsconsulting.com"
    android:autoLink="web"
    android:layout_marginTop="10dp"
    app:layout_constraintTop_toBottomOf="@+id/imageView6"
    android:layout_marginBottom="16dp"
    app:layout_constraintBottom_toTopOf="@+id/textView4"
    app:layout_constraintVertical_bias="0.0"
    android:layout_marginLeft="8dp"
    app:layout_constraintLeft_toLeftOf="@+id/imageView6"
    android:layout_marginRight="8dp"
    app:layout_constraintRight_toRightOf="@+id/imageView6"
    android:textAppearance="@style/Body" />

除第二封电子邮件 (hr@opsconsulting.com) 外,所有这些都被识别为电子邮件。我做了一些研究,在查看 linkify 类时,android 指出“指示电子邮件地址的位字段应在采用选项掩码的方法中匹配;常量值:2 (0x00000002)。”

我对编程很陌生,我不明白这意味着什么,但我猜这与我的问题有关。

结论:“hr@opsconsulting.com”不会被识别为电子邮件,因为@符号前只有两个字符,我如何使所述电子邮件被识别为电子邮件并直接发送到 gmail 应用程序。

谢谢!

【问题讨论】:

    标签: android xml email linkify


    【解决方案1】:

    有人回答了这个问题,但在我尝试时将其删除,并且成功了!

    这是建议的解决方案:

        TextView feedback = (TextView) findViewById(R.id.textView);
        feedback.setText(Html.fromHtml("<a href=\"mailto:ex@example.com\">Wanted Text</a>"));
        feedback.setMovementMethod(LinkMovementMethod.getInstance());
    

    textView 是您要链接的 textView 的 ID,ex@example.com 是所需的电子邮件收件人,Wanted Text 是您要向用户显示的文本。

    感谢给我这个解决方案的人!

    【讨论】:

      【解决方案2】:

      这个Html.fromHtml("&lt;a href=\"mailto:ex@example.com\"&gt;Wanted Text&lt;/a&gt;") 不起作用。不确定这是否是正确的写作方式:&lt;a href=\"mailto:ex@example.com\"&gt;Wanted Text&lt;/a&gt;

      【讨论】:

        猜你喜欢
        • 2021-04-14
        • 2013-11-25
        • 2015-11-06
        • 1970-01-01
        • 2014-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多