it to inflate your menu:

@Override 

public boolean onCreateOptionsMenu(Menu menu) {

 theMenu = menu;

 new MenuInflater(getApplication()).

  inflate(R.menu.sample, menu);

 return(super.onCreateOptionsMenu (menu));

}

CHAPTER 12

Fonts

Inevitably, you’ll get the question “Hey, can we change this font?” when doing application development. The answer depends on what fonts come with the platform, whether you can add other fonts, and how to apply them to the widget or whatever needs the font change.

Android is no different. It comes with some fonts plus a means for adding new fonts. Though, as with any new environment, there are a few idiosyncrasies to deal with.

Love the One You’re With

Android natively knows three fonts, by the shorthand names of “sans”, “serif”, and “monospace”. These fonts are actually the Droid series of fonts, created for the Open Handset Alliance by Ascender.[14]

For those fonts, you can just reference them in your layout XML, if you so choose. The following layout from the Fonts/FontSampler sample project shows example code, and can also be found in the Source Code area at http://apress.com:

<?xml version='1.0' encoding='utf-8'?>

<TableLayout

 xmlns:android='http://schemas.android.com/apk/res/android'

 android:layout_width='fill_parent'

 android:layout_height='fill_parent'

 android:stretchColumns='1'>

 <TableRow>

  <TextView

   android:text='sans:'

   android:layout_marginRight='4px'

   android:textSize='20sp'

  />

  <TextView

   android:id='@+id/sans'

   android:text='Hello, world!'

   android:typeface='sans'

   android:textSize='20sp'

  />

 </TableRow>

 <TableRow>

  <TextView

   android:text='serif:'

   android:layout_marginRight='4px'

   android:textSize='20sp'

  />

  <TextView

   android:id='@+id/serif'

   android:text='Hello, world!'

   android:typeface='serif'

   android:textSize='20sp'

  />

 </TableRow>

 <TableRow>

  <TextView

   android:text='monospace:'

   android:layout_marginRight='4px'

   android:textSize='20sp'

  />

  <TextView

   android:id='@+id/monospace'

   android:text='Hello, world!'

   android:typeface='monospace'

   android:textSize='20sp'

  />

 </TableRow>

 <TableRow>

  <TextView

   android:text='Custom:'

   android:layout_marginRight='4px'

   android:textSize='20sp'

  />

  <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 (e.g., “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.

Вы читаете Beginning Android
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату