| | |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.text.Editable; |
| | | import android.text.Spannable; |
| | | import android.text.SpannableStringBuilder; |
| | | import android.text.Spanned; |
| | | import android.text.TextPaint; |
| | | import android.text.TextUtils; |
| | | import android.text.TextWatcher; |
| | |
| | | import android.text.method.LinkMovementMethod; |
| | | import android.text.method.PasswordTransformationMethod; |
| | | import android.text.style.ClickableSpan; |
| | | import android.text.style.StyleSpan; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | import android.widget.TextView; |
| | | |
| | |
| | | * @param textView 当前组件 |
| | | */ |
| | | private void setStringDifferentColors(TextView textView) { |
| | | try { |
| | | |
| | | if (textView == null) { |
| | | return; |
| | | |
| | | if (textView == null) { |
| | | return; |
| | | } |
| | | |
| | | String s = textView.getText().toString(); |
| | | if (!s.contains("《")) { |
| | | return; |
| | | } |
| | | |
| | | int startIndex1 = s.indexOf("《"); |
| | | int endIndex1 = s.indexOf("》") + 1; |
| | | |
| | | |
| | | int startIndex2 = s.lastIndexOf("《"); |
| | | int endIndex2 = s.lastIndexOf("》") + 1; |
| | | if (UserConfigManage.getInstance().getCurrentAppLanguage().equals(LocalManageUtil.en)) { |
| | | s = s.replace("《", "").replace("》", ""); |
| | | endIndex1 -= 1; |
| | | startIndex2 -= 2;//移除"《"和"》"总长度发生变化,索引也改变; |
| | | endIndex2 -= 4;//移除"《"和"》"总长度发生变化,索引也改变; |
| | | } |
| | | SpannableStringBuilder spannable = new SpannableStringBuilder(s); |
| | | //设置文字的前景色 |
| | | if (textView.getTag() != null && textView.getTag().toString().equals("click")) { |
| | | spannable.setSpan(new ClickableSpan() { |
| | | @Override |
| | | public void onClick(@NonNull View widget) { |
| | | //todo 需要跳转到服务协议界面 |
| | | Intent intent = new Intent(); |
| | | intent.putExtra("type", WebActivity.ServiceAgreement); |
| | | intent.setClass(_mActivity, WebActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | |
| | | @Override |
| | | public void updateDrawState(@NonNull TextPaint ds) { |
| | | super.updateDrawState(ds); |
| | | //设置字体颜色 |
| | | ds.setColor(getResources().getColor(R.color.text_245EC3, null)); |
| | | // 去掉下划线 |
| | | ds.setUnderlineText(false); |
| | | } |
| | | |
| | | |
| | | }, startIndex1, endIndex1, 0); |
| | | spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), startIndex1, endIndex1, 0); |
| | | |
| | | spannable.setSpan(new ClickableSpan() { |
| | | @Override |
| | | public void onClick(@NonNull View widget) { |
| | | //todo 需要跳转到隐私界面 |
| | | Intent intent = new Intent(); |
| | | intent.putExtra("type", WebActivity.PrivacyAgreement); |
| | | intent.setClass(_mActivity, WebActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | |
| | | @Override |
| | | public void updateDrawState(@NonNull TextPaint ds) { |
| | | super.updateDrawState(ds); |
| | | //设置字体颜色 |
| | | ds.setColor(getResources().getColor(R.color.text_245EC3, null)); |
| | | // 去掉下划线 |
| | | ds.setUnderlineText(false); |
| | | } |
| | | |
| | | |
| | | }, startIndex2, endIndex2, 0); |
| | | spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), startIndex2, endIndex2, 0); |
| | | |
| | | |
| | | } |
| | | textView.setText(spannable); |
| | | //中途遇到点击后字体显示高亮,取消高亮 |
| | | textView.setHighlightColor(getResources().getColor(R.color.text_00000000, null)); |
| | | //最后设置可点击,必须实现,否则只能显示样式,无法实现点击效果 |
| | | textView.setMovementMethod(LinkMovementMethod.getInstance()); |
| | | } catch (Exception ignored) { |
| | | } |
| | | |
| | | String s = textView.getText().toString(); |
| | | if (!s.contains("《")) { |
| | | return; |
| | | } |
| | | int startIndex1 = s.indexOf("《"); |
| | | int endIndex1 = s.indexOf("》") + 1; |
| | | |
| | | int startIndex2 = s.lastIndexOf("《"); |
| | | int endIndex2 = s.lastIndexOf("》") + 1; |
| | | |
| | | SpannableStringBuilder spannable = new SpannableStringBuilder(s); |
| | | //设置文字的前景色 |
| | | if (textView.getTag() != null && textView.getTag().toString().equals("click")) { |
| | | spannable.setSpan(new ClickableSpan() { |
| | | @Override |
| | | public void onClick(@NonNull View widget) { |
| | | //todo 需要跳转到服务协议界面 |
| | | Intent intent = new Intent(); |
| | | intent.putExtra("type", WebActivity.ServiceAgreement); |
| | | intent.setClass(_mActivity, WebActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | |
| | | @Override |
| | | public void updateDrawState(@NonNull TextPaint ds) { |
| | | super.updateDrawState(ds); |
| | | //设置字体颜色 |
| | | ds.setColor(getResources().getColor(R.color.text_245EC3, null)); |
| | | // 去掉下划线 |
| | | ds.setUnderlineText(false); |
| | | } |
| | | |
| | | |
| | | }, startIndex1, endIndex1, 0); |
| | | |
| | | spannable.setSpan(new ClickableSpan() { |
| | | @Override |
| | | public void onClick(@NonNull View widget) { |
| | | //todo 需要跳转到隐私界面 |
| | | Intent intent = new Intent(); |
| | | intent.putExtra("type", WebActivity.PrivacyAgreement); |
| | | intent.setClass(_mActivity, WebActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | |
| | | @Override |
| | | public void updateDrawState(@NonNull TextPaint ds) { |
| | | super.updateDrawState(ds); |
| | | //设置字体颜色 |
| | | ds.setColor(getResources().getColor(R.color.text_245EC3, null)); |
| | | // 去掉下划线 |
| | | ds.setUnderlineText(false); |
| | | } |
| | | |
| | | |
| | | }, startIndex2, endIndex2, 0); |
| | | |
| | | |
| | | } |
| | | textView.setText(spannable); |
| | | //中途遇到点击后字体显示高亮,取消高亮 |
| | | textView.setHighlightColor(getResources().getColor(R.color.text_00000000, null)); |
| | | //最后设置可点击,必须实现,否则只能显示样式,无法实现点击效果 |
| | | textView.setMovementMethod(LinkMovementMethod.getInstance()); |
| | | |
| | | } |
| | | |