This may sound a bit fishy but, even i dont know if this is possible in android or not. The requirement is i need to write two languages in the edittext, one urdu and the other is default english, now the problem is in the typeface, since i have to use the urdu typeface as a default, i used setTypeface like the following:
editText.setTypeface(englishFont);
But the problem is the english in this typeface is not good, in fact it is smaller than usual for this i have to use another typeface for English, but this creates the problem, i get the getText from the editText, detect the urdu and english characters and then use spannableStringBuilder to change the typeface accordingly as following:
if(Arrays.asList(urduCodes).contains(Integer.toHexString(text.charAt(i)).toUpperCase()))
{
System.out.println("different: "+text.charAt(i));
SpannableStringBuilder urduBLD;
urduBLD = new SpannableStringBuilder("");
urduBLD.append(edi.getText().charAt(i));
System.out.println("urduBLD: "+urduBLD);
urduBLD.setSpan(new StyleSpan(urduFont.getStyle()),urduBLD.length(),urduBLD.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
stringBuilder.append(urduBLD);
} else
{
System.out.println(text.charAt(i)+"-Code:"+(int)text.charAt(i)+"-"+Integer.toHexString(text.charAt(i)));
SpannableStringBuilder engBLD;
engBLD = new SpannableStringBuilder("");
engBLD.append(edi.getText().charAt(i));
System.out.println("engBLD: "+engBLD);
engBLD.setSpan(new StyleSpan(englishFont.getStyle()),engBLD.length(),engBLD.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
stringBuilder.append(engBLD);
}
But this does not solve the problem, the text in editText remains the same, no change in typeface. Is this possible or not??