mac
2024-07-19 bc072347eb7537d12827e2d215ff57a536016f4a
app/src/main/java/com/hdl/photovoltaic/ui/LoginActivity.java
@@ -4,7 +4,9 @@
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;
@@ -12,6 +14,8 @@
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;
@@ -440,6 +444,8 @@
     * @param textView 当前组件
     */
    private void setStringDifferentColors(TextView textView) {
        try {
        if (textView == null) {
            return;
@@ -449,12 +455,19 @@
        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")) {
@@ -479,6 +492,7 @@
            }, startIndex1, endIndex1, 0);
                spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), startIndex1, endIndex1, 0);
            spannable.setSpan(new ClickableSpan() {
                @Override
@@ -501,6 +515,7 @@
            }, startIndex2, endIndex2, 0);
                spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), startIndex2, endIndex2, 0);
        }
@@ -509,6 +524,8 @@
        textView.setHighlightColor(getResources().getColor(R.color.text_00000000, null));
        //最后设置可点击,必须实现,否则只能显示样式,无法实现点击效果
        textView.setMovementMethod(LinkMovementMethod.getInstance());
        } catch (Exception ignored) {
        }
    }