我使用以下代码更改了阿拉伯音音符号的颜色:

List<String> arabicV = Arrays.asList("ؘ","ؙ","ؚ","ؐ","ؐؑ","ؒ","ؓ","ؔ","ؕ","ؖ","ؗ","ؗ","ﹰﹰ","ﹲ","ﹴ","ﹸ","ﹼ","ﹾ",
            "ٍ","ً","ُ","ِ","َ","ّ","ٓ","ٔ","ْ","ِ","َّ","َ","َْ","َ","ً","ٌ","َ","ُ","ٍ"
            ,"َ","ْ","ِ","ُ","ّ","ً");

    for (int j = 0; j < myString.length; j++) {
        if (arabicV.contains(myString.substring(j, j + 1))) {
             wordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#FF0000")),
                                        j, j+1 , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

                            }

                        }


可以在我的设备上正常运行,如下所示:

android - 在某些手机上无法使用跨距字符串更改阿拉伯音调符号的颜色-LMLPHP

但是在某些设备(例如LG-G5)上,它无法正常工作。像这样:

android - 在某些手机上无法使用跨距字符串更改阿拉伯音调符号的颜色-LMLPHP

有谁知道如何解决此问题或任何其他替代方法?

最佳答案

我找到了答案,有一种方法可以在所有设备上正确设置:

SpannedString result = new SpannedString("");
            for (int j=0;j<myString.length();j++){
                Spannable wordtoSpan = new SpannableString(myString.substring(j,j+1));
                if (arabicV.contains(myString.substring(j,j+1))) {
                    wordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor("#FF0000")),
                            0, 1, 0);

                }
                else
                {
                    wordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor( "#000000")),
                            0, 1, 0);
                }
                result = (SpannedString) TextUtils.concat(result,"",wordtoSpan);
            }

关于android - 在某些手机上无法使用跨距字符串更改阿拉伯音调符号的颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51229862/

10-10 12:49