Как изменить цвет арабского диакритического знака с помощью регулярных выражений в программировании Android? Например: https://i.stack.imgur.com/jdjoH.png
Я использовал замену spannable строки и Html.fromHtml, но не очень хорошо работает.
Вот мой код с регулярным выражением:
List<String> arabic= Arrays.asList("ؘ","ؙ","ؚ","ؐ","ؐؑ","ؒ","ؓ","ؔ","ؕ","ؖ","ؗ","ؗ","ﹰﹰ","ﹲ","ﹴ","ﹸ","ﹼ","ﹾ",
"ٍ","ً","ُ","ِ","َ","ّ","ٓ","ٔ","ْ","ِ","َّ","َ","َْ","َ","ً","ٌ","َ","ُ","ٍ"
,"َ","ْ","ِ","ُ","ّ","ً");
TextView name = (TextView) view.findViewById(R.id.storyman);
name.setText(makeSpannable("AllStringfromdatabase", arabic"));
public SpannableStringBuilder makeSpannable(String text, String regex) {
StringBuffer sb = new StringBuffer();
SpannableStringBuilder spannable = new SpannableStringBuilder();
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
sb.setLength(0);
String group = matcher.group();
String spanText = group.substring(1, group.length() - 1);
matcher.appendReplacement(sb, spanText);
spannable.append(sb.toString());
int start = spannable.length() - spanText.length();
spannable.setSpan(new ForegroundColorSpan(Color.RED), start, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
sb.setLength(0);
matcher.appendTail(sb);
spannable.append(sb.toString());
return spannable;
}