You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从带链接的TextView启动Activity?配置问题排查

问题分析与解决方案

首先,咱们来看你配置里的核心问题:AndroidManifest中<data>标签的写法错误。你把完整的URI com.myapp://register直接填给了android:scheme,但scheme字段只需要填协议部分(也就是com.myapp),剩下的register应该作为host或者path来配置,这样系统才能正确匹配到对应的Activity。

接下来给你一步步修正:

1. 修正AndroidManifest的Intent Filter配置

把原来的<data>标签拆分成scheme和host(推荐这种方式,逻辑更清晰),修改后的代码如下:

<activity android:name=".Activites.RegisterViewPagerActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <!-- 拆分scheme和host,匹配com.myapp://register这个URI -->
        <data 
            android:scheme="com.myapp"
            android:host="register" />
    </intent-filter>
</activity>

如果你更倾向于用path来匹配,也可以这么写(注意字符串里的href要对应调整):

<activity android:name=".Activites.RegisterViewPagerActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data 
            android:scheme="com.myapp"
            android:path="/register" />
    </intent-filter>
</activity>

对应的字符串资源里的href要改成com.myapp:///register(三个斜杠,因为host为空,path为/register)。

2. 确保TextView能响应点击(无需Java代码)

光改Manifest还不够,TextView默认不会处理自定义scheme的链接点击,你需要在TextView的XML布局里添加几个属性,完全不用写Java代码:

<TextView
    android:id="@+id/tv_register"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/register"
    <!-- 让TextView识别链接 -->
    android:autoLink="all"
    <!-- 允许链接可点击 -->
    android:linksClickable="true"
    <!-- 设置处理链接点击的核心方法 -->
    android:movementMethod="android.text.method.LinkMovementMethod" />

这样配置后,当用户点击TextView里的“Sign Up”链接时,系统就会自动匹配到你配置的RegisterViewPagerActivity,完全符合你“仅在配置文件实现逻辑”的需求。

内容的提问来源于stack exchange,提问作者abrutsze

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:59:45