我使用以下代码更改了阿拉伯音音符号的颜色:
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);
}
}
像这样在我的设备上运行正常:
,但是在某些设备(例如LG-G5)上,它不起作用。像这样:
有人知道如何解决此问题或其他替代方法吗?
答案 0 :(得分:1)
我找到了答案,有一种方法可以在所有设备上正确设置:
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);
}