tailieunhanh - Bắt Đầu Với Android (P.4)

Tham khảo tài liệu 'bắt đầu với android ()', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Page 127 Friday April 10 2009 3 34 PM CHAPTER 12 FONTS 127 TextView android id @ id custom android text Hello world android textSize 20sp TableRow TableLayout This layout builds a table showing short samples of four fonts. Notice how the first three have the android typeface attribute whose value is one of the three built-in font faces . sans . The three built-in fonts are very nice. However it may be that a designer or a manager or a customer wants a different font than one of those three. Or perhaps you want to use a font for specialized purposes such as a dingbats font instead of a series of PNG graphics. The easiest way to accomplish this is to package the desired font s with your application. To do this simply create an assets folder in the project root and put your TrueType TTF fonts in the assets. You might for example create assets fonts and put your TTF files in there. Then you need to tell your widgets to use that font. Unfortunately you can no longer use layout XML for this since the XML does not know about any fonts you may have tucked away as an application asset. Instead you need to make the change in Java code public class FontSampler extends Activity Override public void onCreate Bundle icicle icicle setContentView TextView tv TextView findViewById Typeface face getAssets fonts face Here we grab the TextView for our custom sample then create a Typeface object via the static createFromAsset builder method. This takes the application s AssetManager from getAssets and a path within your assets directory to the font you want. Then it is just a matter of telling the TextView to setTypeface providing the Typeface you just created. In this case we are using the Handmade Typewriter2 font see Figure 12-1 . 2. http typoasis designers klein07 text01 Page 128 Friday April 10 2009 3 34 PM

TỪ KHÓA LIÊN QUAN