public class Test10Activity extends Activity {
TextView textView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test10);
textView = (TextView) findViewById(R.id.text);
String webLinkText = "<a href='https://souly.cn'> html超链接测试</a>" ;
textView.setText(Html.fromHtml(webLinkText));
}
}
String webLinkText = "<font color='#333333'><a href='https://souly.cn' style='text-decoration:none; color:#0000FF'> html超链接测试</a>" ;
<TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:text="souly.cn" android:autoLink="email|phone|web" />
public abstract class ClickableSpan extends CharacterStyle implements UpdateAppearance {
/
* Performs the click action associated with this span.
*/
public abstract void onClick(View widget);
/
* Makes the text underlined and in the link color.
*/
@Override
public void updateDrawState(TextPaint ds) {
ds.setColor(ds.linkColor);
ds.setUnderlineText(true);
}
}
public class Test10Activity extends Activity {
TextView textView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test10);
textView = (TextView) findViewById(R.id.text);
String webLinkText = "我的博客-->https://souly.cn" ;
textView.setText(webLinkText);
NoUnderlineSpan mNoUnderlineSpan = new NoUnderlineSpan();
if (textView.getText() instanceof Spannable) {
Spannable s = (Spannable) textView.getText();
s.setSpan(mNoUnderlineSpan, 0, s.length(), Spanned.SPAN_MARK_MARK);
}
}
public static class NoUnderlineSpan extends UnderlineSpan {
public NoUnderlineSpan() {}
public NoUnderlineSpan(Parcel src) {}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}
}
public class Test10Activity extends Activity {
TextView textView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test10);
textView = (TextView) findViewById(R.id.text);
String webLinkText = "我的博客" ;
SpannableString text = new SpannableString(webLinkText);
NoUnderlineSpan mNoUnderlineSpan = new NoUnderlineSpan("https://souly.cn") ;
text.setSpan(mNoUnderlineSpan,0,text.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(text);
textView.setMovementMethod(LinkMovementMethod.getInstance());
}
public static class NoUnderlineSpan extends URLSpan {
public NoUnderlineSpan(String url) {
super(url);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}
}
public class Test10Activity extends Activity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test10);
textView = (TextView) findViewById(R.id.text);
String webLinkText = "我的博客";
SpannableString spStr = new SpannableString(webLinkText);
ClickableSpan clickSpan = new NoLineClickSpan(spStr.toString()); //设置超链接
spStr.setSpan(clickSpan, 0, spStr.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textView.append(spStr);
textView.setMovementMethod(LinkMovementMethod.getInstance());
}
private class NoLineClickSpan extends ClickableSpan {
String text;
public NoLineClickSpan(String text) {
super();
this.text = text;
}
@Override
public void updateDrawState(TextPaint ds) {
ds.setColor(ds.linkColor);
ds.setUnderlineText(false); //去掉下划线
}
@Override
public void onClick(View widget) {
processHyperLinkClick(text); //点击超链接时调用
}
}
private void processHyperLinkClick(String text){
Toast.makeText(this,text,Toast.LENGTH_SHORT).show();
}
}
<intent-filter> <action android:name="com.example.project.SHOW_CURRENT" /> <action android:name="com.example.project.SHOW_RECENT" /> <action android:name="com.example.project.SHOW_PENDING" /> . . . </intent-filter>
<intent-filter> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> . . . </intent-filter>
<intent-filter> <data android:mimeType="video/mpeg" android:scheme="http" /> <data android:mimeType="audio/mpeg" android:scheme="http" /> . . . </intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT"></category>
<action android:name="android.intent.action.VIEW"></action>
<data android:host="profile" android:scheme="mxn"/>
</intent-filter>
public class Test9Activity extends Activity {
private String uid;
private static final Uri PROFILE_URI = Uri.parse("mxn://profile");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test8);
extractUidFromUri();
}
private void extractUidFromUri() {
Uri uri = getIntent().getData();
if (uri != null && PROFILE_URI.getScheme().equals(uri.getScheme())) {
uid = uri.getQueryParameter("uid");
Log.d("=====", "uid from url: " + uid);
}
}
}
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="【谷歌母公司Alphabet市值超苹果:全球第一】据外媒报道,@谷歌 母公司 @Alphabet
通过公司分拆以及搜索广告业务的持续强势,股价继续攀升。美国时间周一,Alphabet的公司市值已超过了 @苹果 ,
成为全世界市值最大的公司. www.google.com"
/>
</RelativeLayout>
public class Test10Activity extends Activity {
TextView textView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test10);
textView = (TextView) findViewById(R.id.text);
Pattern p = Pattern.compile("@(\w+?)(?=\W|$)(.)");
Linkify.addLinks(textView, p, "mxn://profile?uid=");
}
}
public class Test9Activity extends Activity {
private String uid;
private static final Uri PROFILE_URI = Uri.parse("mxn://profile");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test8);
extractUidFromUri();
}
private void extractUidFromUri() {
Uri uri = getIntent().getData();
if (uri != null && PROFILE_URI.getScheme().equals(uri.getScheme())) {
uid = uri.getQueryParameter("uid");
Log.d("=====", "uid from url: " + uid);
}
}
}
public class Test10Activity extends Activity {
TextView textView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test10);
textView = (TextView) findViewById(R.id.text);
Pattern p = Pattern.compile("@(\w+?)(?=\W|$)(.)");
Linkify.addLinks(textView, Linkify.WEB_URLS);
Linkify.addLinks(textView, p, "mxn://profile?uid=");
}
}
public class Test10Activity extends Activity {
TextView textView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test10);
textView = (TextView) findViewById(R.id.text);
Pattern mentionsPattern = Pattern.compile("@(\w+?)(?=\W|$)(.)");
String mentionsScheme = String.format("%s/?%s=", "mxn://profile", "uid");
Linkify.addLinks(textView, Linkify.WEB_URLS);
Linkify.addLinks(textView, mentionsPattern, mentionsScheme) ;
stripUnderlines(textView) ;
}
private class URLSpanNoUnderline extends URLSpan {
public URLSpanNoUnderline(String url) {
super(url);
}
@Override public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}
private void stripUnderlines(TextView textView) {
Spannable s = (Spannable)textView.getText();
URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
for (URLSpan span: spans) {
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
s.removeSpan(span);
span = new URLSpanNoUnderline(span.getURL());
s.setSpan(span, start, end, 0);
}
textView.setText(s);
}
}
class MyMatchFilter implements MatchFilter {
public boolean acceptMatch(CharSequence s, int start, int end) {
return s.charAt(end-1) != '.';
}
}
class MyTransformFilter implements TransformFilter {
public String transformUrl(Matcher match, String url) {
return url.toLowerCase();
}
}
public class Test10Activity extends Activity {
TextView textView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test10);
textView = (TextView) findViewById(R.id.text);
Pattern mentionsPattern = Pattern.compile("@(\w+?)(?=\W|$)(.)");
String mentionsScheme = String.format("%s/?%s=", "mxn://profile", "uid");
Linkify.addLinks(textView, Linkify.WEB_URLS);
// Linkify.addLinks(textView, mentionsPattern, mentionsScheme) ;
Linkify.addLinks(textView, mentionsPattern, mentionsScheme, new Linkify.MatchFilter() {
@Override
public boolean acceptMatch(CharSequence s, int start, int end) {
return s.charAt(end-1) != '.';
}
}, new Linkify.TransformFilter() {
@Override
public String transformUrl(Matcher match, String url) {
return url.toLowerCase();
}
});
stripUnderlines(textView) ;
}
private class URLSpanNoUnderline extends URLSpan {
public URLSpanNoUnderline(String url) {
super(url);
}
@Override public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}
private void stripUnderlines(TextView textView) {
Spannable s = (Spannable)textView.getText();
URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
for (URLSpan span: spans) {
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
s.removeSpan(span);
span = new URLSpanNoUnderline(span.getURL());
s.setSpan(span, start, end, 0);
}
textView.setText(s);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有