类似于验证码倒计时的计时器:CountDownTimer类
private CountDownTimer authCountDownTimer;
authCountDownTimer = new CountDownTimer(61 * 1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
// 每一次倒计时对应的操作
}
@Override
public void onFinish() {
// 计时结束,对应操作
}
}.start();
同一个textView不同颜色文字混排
1.使用Html标签进行实现
String str="默认颜色<font color='#FF0000'>红颜色</font>";
tv.setText(Html.fromHtml(str));
2.使用SpannableString类
SpannableString styledText = new SpannableString("默认颜色,红颜色");
styledText.setSpan(new TextAppearanceSpan(this, R.style.style0), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
styledText.setSpan(new TextAppearanceSpan(this, R.style.style1), 4, 6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mTextView.setText(styledText, TextView.BufferType.SPANNABLE);