Android TextView使http和自定义方案URL可点击

Android TextView使http和自定义方案URL可点击,android,android-intent,linkify,custom-scheme-url,Android,Android Intent,Linkify,Custom Scheme Url,我正在创建一个android应用程序,并定义了如下活动: <activity android:name="com.scheme.app.MainActivity" android:screenOrientation="portrait" android:theme="@style/MainActivityTheme"> <intent-filter> <action android:name="android.inte

我正在创建一个android应用程序,并定义了如下活动:

<activity
    android:name="com.scheme.app.MainActivity"
    android:screenOrientation="portrait"
    android:theme="@style/MainActivityTheme">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data
            android:host="invite"
            android:scheme="schemeapp" />
        <category android:name="android.intent.category.BROWSABLE" />
    </intent-filter>
</activity>
我需要创建web url()以及自定义url(schemeapp://invite)可点击

我已经尝试过的:

String text = "Testing custom scheme - schemeapp://invite with http http://www.LMNGTFY.com";
textView.setText(text);
Linkify.addLinks(textView, Linkify.WEB_URLS | Linkify.PHONE_NUMBERS | Linkify.EMAIL_ADDRESSES | Linkify.ALL);
Pattern urlDetect = Pattern.compile("(schemeapp):\\/\\/([a-zA-Z0-9.]+)");
Matcher matcher = urlDetect.matcher(text);
String scheme = null;

while (matcher.find()) {
    String customSchemedUrl = matcher.group(0);
    Uri uri = Uri.parse(customSchemedUrl);
    scheme = uri.getScheme();
    break;
}

if (!TextUtils.isEmpty(scheme)) {
    Linkify.addLinks(textView, urlDetect, scheme);
}
如果我删除以下代码行以检测web url,则自定义方案url将起作用:

Linkify.addLinks(textView, Linkify.WEB_URLS | Linkify.PHONE_NUMBERS | Linkify.EMAIL_ADDRESSES | Linkify.ALL);
如果我尝试将http添加为自定义方案url,则http url不可单击

编辑:澄清

我不能使用HTML,因为用户输入也会显示在TextView上,需要链接

你能帮忙吗。 谢谢

这是一个选项:

final Spanned html = Html.fromHtml("Testing custom scheme - <a href='schemeapp://invite'>schemeapp://invite</a> with http http://www.LMNGTFY.com";);

helpText.setText(html);
helpText.setMovementMethod(new LinkMovementMethod());
final-span html=html.fromHtml(“测试自定义方案-使用httphttp://www.LMNGTFY.com";);
setText(html);
setMovementMethod(新的LinkMovementMethod());

谢谢,这会有用,但我不能放入html,textview也会显示用户的输入,因此他们不会使用html标记。您可以像userinput.replace(“schemeapp://.*)一样预处理文本,“在我们的iPhone应用程序上进行同样的测试,因为内容是跨平台的。。当然可以,但在设置文本视图之前,您可以在android上进行预处理。我必须进行一些处理,但这是使其在所有情况下都能正常工作的唯一方法。@ligi感谢您的努力。”。
final Spanned html = Html.fromHtml("Testing custom scheme - <a href='schemeapp://invite'>schemeapp://invite</a> with http http://www.LMNGTFY.com";);

helpText.setText(html);
helpText.setMovementMethod(new LinkMovementMethod());