模仿新浪微博@某人/#话题的效果

来源:互联网 发布:数据库手机号码类型 编辑:程序博客网 时间:2024/04/29 23:42
1.
Pattern wikiWordMatcher = Pattern.compile("(http://|ftp://|https://|www.){0,1}[a-zA-Z0-9\\-\\.]+?\\.(org|edu|uk|hk|com|net|cn|me|tw|fr|be)[^\\s]*");  //定义正则表达式
String mentionsScheme = String.format("%s/?%s=",Constants.MENTIONS_SCHEMA, Constants.PARAM_UID);  //格式化字符串,指定跳转意图
Linkify.addLinks(textView, wikiWordMatcher, mentionsScheme);  //将TextView的字符串根据正则去替换为链接

2.
然后在清单文件中修改要跳转的Activity的意图
<activity android:name="com.xxx.xx.XxxActivity">
            <intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="scheme" android:host="host"/>
</intent-filter>
</activity> 

3.
然后在跳转的目标页面通过 getIntent().getData().getQueryParameter("key");获取参数后进行处理

ps:意图中可以使用schema://host:port/path?key=value的方式来传递参数
0 0
原创粉丝点击