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?
Asked
Active
Viewed 1,815 times
1
-
You may look into `EditText` instead and disable any type of input. – Si8 Sep 24 '13 at 18:39
-
Using two different fonts (or typefaces) in a single `TextView` can be as easy as building a `Spannable` out of the individual pieces and applying two [`TypefaceSpan`](http://developer.android.com/reference/android/text/style/TypefaceSpan.html)s. – MH. Sep 24 '13 at 19:23
-
1@SiKni8 is it possible to add multiple fonts in a single edittext? – chossen-addict Sep 24 '13 at 19:29
-
@chossen-addict I added an answer for you. The link is also very helpful :) – Si8 Sep 24 '13 at 19:51
-
@MH Yes you are right but why don't you help others by providing a link to sample usage of `TypeSpans` and reducing further googling. e.g. http://stackoverflow.com/questions/6612316/how-set-spannable-object-font-with-custom-font/10741161#10741161 – johnkarka May 21 '15 at 20:47
2 Answers
1
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
-
I meant font , so what you are suggesting that its not possible? Isnt there any work around? – chossen-addict Sep 24 '13 at 19:30
0
You can try something like this:
mBox = new TextView(context);
mBox.setText(Html.fromHtml("<b>" + title + "</b>" + "<br />" +
"<small>" + description + "</small>" + "<br />" +
"<small>" + DateAdded + "</small>"));
taken from here: Is it possible to have multiple styles inside a TextView?