| | |
| | | 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 (!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")) { |
| | |
| | | |
| | | |
| | | }, startIndex1, endIndex1, 0); |
| | | spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), startIndex1, endIndex1, 0); |
| | | |
| | | spannable.setSpan(new ClickableSpan() { |
| | | @Override |
| | |
| | | |
| | | |
| | | }, startIndex2, endIndex2, 0); |
| | | spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), startIndex2, endIndex2, 0); |
| | | |
| | | |
| | | } |
| | |
| | | textView.setHighlightColor(getResources().getColor(R.color.text_00000000, null)); |
| | | //最后设置可点击,必须实现,否则只能显示样式,无法实现点击效果 |
| | | textView.setMovementMethod(LinkMovementMethod.getInstance()); |
| | | } catch (Exception ignored) { |
| | | } |
| | | |
| | | } |
| | | |