我们先来看下效果图:
直接上代码:
mainactivity.java
package com.qfy.linksdemo;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.TextAppearanceSpan;
import android.view.View;
import android.widget.CheckBox;
public class MainActivity extends Activity {
private CheckBox cbAgreement;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cbAgreement = findViewById(R.id.cb_agreement);
setAgreement();
}
private void setAgreement() {
SpannableString msp = new SpannableString("我阅读并同意《扬宏豕慧使用协议》和《腾讯开发平台的开户协议》");
int length = msp.length();
//设置字体前景色
msp.setSpan(new ForegroundColorSpan(Color.parseColor("#555555")), 0, 6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
msp.setSpan(new ForegroundColorSpan(Color.pa