Книга: Beginning Android

Colors

Colors

Colors in Android are hexadecimal RGB values, also optionally specifying an alpha channel.

You have your choice of single-character hex values or double-character hex values, leaving you with four styles:

• #RGB

• #ARGB

• #RRGGBB

• #AARRGGBB

These work similarly to their counterparts in Cascading Style Sheets (CSS).

You can, of course, put these RGB values as string literals in Java source or layout resources. If you wish to turn them into resources, though, all you need to do is add color elements to the resources file, with a name attribute for your unique name for this color, and a single text element containing the RGB value itself:

<resources>
 <color name="yellow_orange">#FFD555</color>
 <color name="forest_green">#005500</color>
 <color name="burnt_umber">#8A3324</color>
</resources>

In a layout, you can reference colors as @color/..., replacing the ellipsis with your unique name for the color (e.g., burnt_umber). In Java, you reference color resources by the unique name prefixed with R.color. (e.g., Resources.getColor(R.color.forest_green)).

Оглавление книги

Оглавление статьи/книги

Генерация: 0.054. Запросов К БД/Cache: 0 / 0
поделиться
Вверх Вниз