I wo开发者_如何学运维uld like to change the font of a RichTextField but I want to change it after the initialization of the Field.
Is it possible?
Font font = Font.getDefault() ;
FontFamily ff;
try
{
ff = FontFamily.forName("arial");
font = ff.getFont(FontFamily.SCALABLE_FONT, 18).derive(Font.BOLD);
field.setFont(font);
}
catch(ClassNotFoundException e)
{
}
If you can obtain the reference to the RichTextField, you can call setFont(Font font)
on it, and then call invalidate()
to force the field to repaint itself. invalidate()
is a protected method, so you're going to have to modify your RichTextField class (extend it) to either update setFon
t to automatically call invalidate
, or provide a public version of invalidate
that you can call.
other way...
try {
myFontFamily = FontFamily.forName("BBAlpha Serif");
Font appFont = myFontFamily.getFont(Font.PLAIN, 6, Ui.UNITS_pt);
field.setFont(appFont );
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
精彩评论