0

我有这个字符串,我使用垃圾邮件类为文本提供颜色,但我没有得到结果,我已经研究过,但没有任何解决方案

    <string name="successfull_registration">
    Please, use the means of 
    payment of the Credit Bank that most suits you. Box Office, 
    Transfer, Cashier or BCP Agent, to make  payment to account
    <span class="blue">0102-0228345543469</span> Pympack SAC \n
    </string>

这里我使用垃圾邮件类

    <span class="blue">0102-0228345543469</span>
4

2 回答 2

2

如果你想使用 span,你可以在 java 中配置:

        SpannableString Spann = new SpannableString ( "your text source" );
        ClickableSpan CSpan = new ClickableSpan (){
            @Override
            public void onClick(View v){
    Toast.makeText(getApplicationContext() , "your clickable",
      Toast.LENGTH_LONG).show();
            }
        };
        
        Spann.setSpan(backgroundSpan, 0, Spann.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        yourTextViewId.setText(Spann);
        yourTextViewId.setMovementMethod(LinkMovementMethod.getInstance());

于 2018-08-29T15:35:17.347 回答
2

请改用 SpannableString。

val string = SpannableString(resources.getString(R.string.successfull_registration))
string.setSpan(
    ForegroundColorSpan(Color.BLUE),
    144,
    162,
    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
  )

textView.text = string
于 2018-08-29T15:08:59.250 回答