如何在android中将文本设置为链接并将该文本传递给其他活动

如何在android中将文本设置为链接并将该文本传递给其他活动,android,android-intent,Android,Android Intent,要将文本设置为链接,我遵循以下步骤[ 但当我点击该文本时,它应该将该文本传递给另一个活动。如何做到这一点 例如,我将一个活动中的一些文本设置为链接,因此当我单击该链接时,它应该转到另一个活动,甚至应该传递文本数据 请有人帮我一下。我是android开发新手。很简单,只要在你想要下一个活动的地方单击一下功能就可以定义它 在OnCREATE下这样定义Onclick 然后在活动中的任意位置编写此函数 } 然后在下一个活动中,通过 然后,您可以在下一个活动中使用字符串变量当您使用Linkify向文本添加

要将文本设置为链接,我遵循以下步骤[

但当我点击该文本时,它应该将该文本传递给另一个活动。如何做到这一点

例如,我将一个活动中的一些文本设置为链接,因此当我单击该链接时,它应该转到另一个活动,甚至应该传递文本数据


请有人帮我一下。我是android开发新手。

很简单,只要在你想要下一个活动的地方单击一下功能就可以定义它

在OnCREATE下这样定义Onclick

然后在活动中的任意位置编写此函数

}

然后在下一个活动中,通过


然后,您可以在下一个活动中使用字符串变量

当您使用Linkify向文本添加链接时,使用如下内容传入一个方案:

private static void linkifyUsername(TextView text){
    Pattern pattern = Pattern.compile("@([a-zA-Z]|[\u4E00-\u9FA5]|[0-9]|_|-)+");
    String scheme = "com.example.app.profile://";
    Linkify.addLinks(text, pattern, scheme);
}
在您的AndroidManifest.xml中,为将接受该链接并使用相同方案的活动放入如下意图过滤器:

<activity android:name=".Profile" android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden"
android:screenOrientation="portrait">
    <intent-filter>
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="com.example.app.profile" />
    </intent-filter>
</activity>

您是指通过webview呈现的文本链接,还是指标签中有文本,希望单击按钮,然后让文本启动另一个活动并转移到该新活动?欢迎..祝您编码愉快
Bundle extras = getIntent().getExtras();
String var="";

      if (extras != null)
      {

        String value= extras.getString("new_variable_name");       
        value= var;

      }
private static void linkifyUsername(TextView text){
    Pattern pattern = Pattern.compile("@([a-zA-Z]|[\u4E00-\u9FA5]|[0-9]|_|-)+");
    String scheme = "com.example.app.profile://";
    Linkify.addLinks(text, pattern, scheme);
}
<activity android:name=".Profile" android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden"
android:screenOrientation="portrait">
    <intent-filter>
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="com.example.app.profile" />
    </intent-filter>
</activity>
Uri data = getIntent().getData();