多种字体到单个文本视图取决于语言 [英] Multiple font to single textview depending on langugage

查看:150
本文介绍了多种字体到单个文本视图取决于语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,目前我有英文文本和阿拉伯文本的文本浏览,我正在做的是应用字体,取决于文本视图中的语言,但有时候,我有英文和阿拉伯文在单个文本,所以如何我可以在同一个Textview上应用阿拉伯文和英文字体吗?
是否有可能将两种字体合并为一种字体类型,并将其应用到每个位置,这样做的工作是什么?

解决方案

<发现这个:

 字符串firstString =AAAAAA:; 
字符串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);

可能工作


So at the moment I have textviews with English text and Arabic text and I am doing is applying font depending what language is in the textview , but there are some times when i have both English and Arabic in single text , so how is it possible for me to apply arabic and english font on the same Textview? Is it possible that i merge two fonts in one font type , and apply it every where, will that work?

解决方案

Found this:

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);

might work

这篇关于多种字体到单个文本视图取决于语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆