TextView设置下划线并拨打电话

2023-02-10 19:06:24 浏览数 (1)

Android小功能  

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

代码语言:javascript复制
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()); 

//设置点击事件

代码语言:javascript复制
  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);
     
    }
   });

0 人点赞