Search code examples
androidfontstextviewfont-face

Multiple font to single textview depending on langugage


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?


Solution

  • 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