android - 如何使 TextView 的每个单词都可点击?

标签 android

伙计们,这是示例文本:“我希望这个 [option1/option2] 可点击。”

当用户点击一个选项(或一个词)时,我会发生什么,我会将点击的词保存到一个变量中。如何使该选项可点击?

感谢任何帮助..

最佳答案

这是一个有你需要的例子的博客 这对我帮助很大。 <强> Link To Blog

来自博客的代码你怎么能做到这一点。

在您的主要 Activity 中以这种方式设置链接。

mTextSample = (TextView) findViewById(R.id.text1);
        text = "<html>Visit my blog <a href=\"http://sherifandroid.blogspot.com\">mysite</a> or run the <a href=\"sherif-activity://myactivity?author=sherif&nick=king\">myactivity</a> callback</html>";  
        mTextSample.setText(Html.fromHtml(text));
        mTextSample.setMovementMethod(LinkMovementMethod.getInstance());

获取参数:

TextView mTextSample = (TextView) findViewById(R.id.text);
        mTextSample.setText(getIntent().getData().getQueryParameter("author"));
        mTextSample = (TextView) findViewById(R.id.text1);
        mTextSample.setText(getIntent().getData().getQueryParameter("nick"));

在 Manifest 中将您的第二个 Activity 声明为:

<activity android:label="@string/app_name" android:name="sherif.android.linkify.example.TestActivity"> 
   <intent-filter> <data android:scheme="sherif-activity" android:host="myactivity"/> 
   <action android:name="android.intent.action.VIEW"/> 
   <category android:name="android.intent.category.DEFAULT"/> 
   <category android:name="android.intent.category.BROWSABLE"/> 
   </intent-filter> 
</activity>

关于android - 如何使 TextView 的每个单词都可点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8078821/

相关文章:

java - Android 包名称

当应用程序在后台时,Android altbeacon 的间隔范围

java - android:使用xml页面创建一个新的 Activity

android - 动态添加 View android

android - 按权限、功能和 Intent 搜索 Android 应用

android - React native 构建失败 : The development server returned response error code 500

javascript - ionic 推送通知 : How to handle onClick?

android - GitHub VCS 未在 Android Studio 中显示

android - 默认情况下选择主从流程中的第一项

android - 如果 android 重新启动服务 onCreate 再次调用?