Android : Change Typeface Of Edit Text For New Text That Is Entered
I want to have different typefaces for different parts of text in the same Edit Text. I have tried doing this to change Typeface : Typeface myFont = Typeface.createFromAsset(getAss
Solution 1:
You are looking for Spannable interface. You can use this to change the font of different part of an EditText or TextView.
This is an example code for you to turn a selected text into ITALIC.
Spannablestr= mBodyText.getText();
if(mBodyText.getSelectionEnd() > mBodyText.getSelectionStart())
str.setSpan(newStyleSpan(android.graphics.Typeface.ITALIC),
mBodyText.getSelectionStart(), mBodyText.getSelectionEnd(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
else
str.setSpan(newStyleSpan(android.graphics.Typeface.ITALIC),
mBodyText.getSelectionEnd(),
mBodyText.getSelectionStart(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Post a Comment for "Android : Change Typeface Of Edit Text For New Text That Is Entered"