I want to set style to selected text from EditText
using custom typeface. I am getting below error at compile time. The constructor StyleSpan(Typeface) is undefined
.
Below code I am applying.
int start=editbox.getSelectionStart();
int end=editbox.getSelectionEnd();
Spannable span=(Spannable)editbox.getText();
StyleSpan f = new StyleSpan(
Typeface.createFromAsset(getAssets(),
"fonts/genbkbasr.ttf"));
span.setSpan(f, start,end, 0);
Thanks.
I wrote a class to work around this limitation. It appeared to work in limited testing, but I haven't yet written the application that I needed it for. Note that it assumes that the custom font is available as an asset, and it makes a static call to retrieve the application's context (which it needs to access the resource). A better approach would be to pass in the Context to the constructor..
Accepted values for this constructor are documented here:
Values should be style constants, like
Typeface.BOLD
.