android - 多种字体到单一 TextView 取决于语言

标签 android fonts textview font-face

所以目前我有带有英文文本和阿拉伯文本的 TextView ,我正在根据 TextView 中的语言应用字体,但有时我在单个文本中同时有英文和阿拉伯文,所以如何我可以在同一个 Textview 上应用阿拉伯语和英语字体吗? 是否可以将两种字体合并为一种字体类型,然后将其应用到任何地方,这行得通吗?

最佳答案

找到这个:

String firstString = "AAAAAA: ";
String secondString = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB";

SpannableStringBuilder sb = new SpannableStringBuilder(firstString + secondString);

sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, firstString.length(),
        Spannable.SPAN_INCLUSIVE_INCLUSIVE);

sb.setSpan(new ForegroundColorSpan(Color.rgb(255, 0, 0)), firstString.length() + 1,
        firstString.length() + secondString.length(),
        Spannable.SPAN_INCLUSIVE_INCLUSIVE);

textView.setText(sb);

可能有用

关于android - 多种字体到单一 TextView 取决于语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18989067/

相关文章:

firefox - Firefox 中 Materialise 的 Roboto 字体显示问题

android - 在 TextView 上膨胀 xml 布局 ArrayIndexOutOfBoundsException 时出错

android - 使用序列化克隆 Android 对象

android - 延时后停止拉动刷新

iphone - UITableViewCell 文本的字体和颜色是什么?

css - Material 图标将 Electron OSX连字

java - Android,从任何 URL/任何文件、avi 等保存。它仅在模拟器上运行,不在 Samsung GalaxyS3 上运行

安卓工作室 || GDK 'hello word' ||导入 com.google.android.glass.app.Card ||无法解析符号 'google'

android - 如何在布局中向右和中间对齐高度

android - Badge TextView 文本未居中对齐