摘自:http://bbs.csdn.net/topics/390998772
需要了这样一个需求:在点击提交按钮的之前,客户需要点击已阅读两个说明书。
实现如下:在一个textview中有两部分文字要颜色要与默认颜色不一样,并且可以点击,并跳转到不同的页面。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package
com.weileek.mytextview;
import
android.content.Context;
import
android.content.Intent;
import
android.graphics.Color;
import
android.text.TextPaint;
import
android.text.style.ClickableSpan;
import
android.view.View;
public
class
ShuoMClickableSpan
extends
ClickableSpan {
String string;
Context context;
public
ShuoMClickableSpan(String str,Context context){
super
();
this
.string = str;
this
.context = context;
}
@Override
public
void
updateDrawState(TextPaint ds) {
ds.setColor(Color.BLUE);
}
@Override
public
void
onClick(View widget) {
Intent intent
=
new
Intent();
intent.setClass(context, TwoActivity.
class
);
context.startActivity(intent);
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
TextView textView = (TextView) findViewById(R.id.textView);
String ttt =
"嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻"
;
String sss =
"哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈"
;
SpannableString spanttt =
new
SpannableString(ttt);
SpannableString spansss =
new
SpannableString(sss);
ClickableSpan clickttt =
new
ShuoMClickableSpan(ttt,
this
);
ClickableSpan clicksss =
new
CopyOfShuoMClickableSpan(ttt,
this
);
spanttt.setSpan(clickttt,
0
, ttt.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
spansss.setSpan(clicksss,
0
, sss.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(
"哈哈"
);
textView.append(spanttt);
textView.append(
"你是谁你谁你是谁你谁你是谁你谁"
);
textView.append(spansss);
textView.append(
"你是谁你谁你是谁你谁你是谁你谁你是谁你谁你是谁你谁"
);
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
http://yunpan.cn/cZmbyUZgWtEd8
提取码 1f47