Generally, when we place text in our own controls, we will use the paint:
Paint paint = new paint (); paint. setantialias (true); paint. settextsize (16 );
However, if you are on a mobile phone with other resolutions and view the text effects, there will be problems,
If debugging is performed on a low-resolution machine on a high-resolution machine, the font size is too small. Otherwise, the font size is too large.
Therefore, you cannot set the text font in the above way, but should use a method similar to textview, such:
Public void settextsize (INT textsize) {context c = getcontext (); resources R; If (C = NULL) r = resources. getsystem (); else r = C. getresources (); int size = (INT) typedvalue. applydimension (typedvalue. complex_unit_sp, textsize, R. getdisplaymetrics (); mtextpaint. settextsize (size );}
This also encourages us to use SP as the measurement unit rather than PX when setting the textview font size.