TextView设置下划线并拨打电话

时间:2022-11-10 12:43:15


Android小功能  


 //设置下划线效果并设置颜色值

TextView tView = new TextView(context);

SpannableString msp2 = new SpannableString(getResources().getString(R.string.standard_tips_phonenumber_for_user));
msp2.setSpan(new UnderlineSpan(), 0, 12, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
msp2.setSpan(new ForegroundColorSpan(Color.rgb(55,160,225)), 0, 12, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tView .setText(msp2);
tView .setMovementMethod(LinkMovementMethod.getInstance());




//设置点击事件


  tView.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_DIAL);
Uri data = Uri.parse("tel:" +"110");
intent.setData(data);
startActivity(intent);

}
});