スタイルを指定することで、背景色や文字の色などを変更できます。
res/valuesにstyle.xmlを作成し、その中にスタイルを定義する方法です。
(style.xmlで無くてもよいらしい)
XMLは以下のような感じで定義します。
#codeprettify{{
?xml version="1.0" encoding="utf-8"?>
resources>
<style name="theme1"> <item name="android:colorBackground">@color/background</item> <item name="android:windowBackground">@drawable/bg_blue</item> </style> <style name="theme2"> <item name="@android:style/Widget.ListView">@color/background</item> <item name="android:windowBackground">@drawable/bg_blue</item> <item name="android:textColor">@color/listTextColor</item> </style>/resources> }}
で、この定義した内容をどこで使うかなんですが、res/layoutで定義する画面のレイアウトやAndroidManifest.xmlで利用します。
AndroidManifest.xmlでは、applicationタグのandroid:themeプロパティに設定します。
#codeprettify{{
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/theme1"> <activity android:name=".DemoActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
}}
Eclipseからだと、AndroidManifest.xmlの「アプリケーション」の項目の「Theme」を指定することになります。
プロパティ | 概要 | 例 |
android:textColor | 文字の色指定 | |
android:textSize | 文字のサイズ指定 | |
android:textStyle | 文字のスタイル指定 | |
android:background | 背景色の指定 | |
android:layout_width | 幅指定 | |
android:layout_height | 高さ指定 | |
android:maxWidth | 最大幅指定 | |
android:maxHeight | 最大高さ指定 | |
android:maxLength | 最大文字数の指定 | |
android:maxLines | 最大行数の指定 | |
android:padding | パディングの指定 | |
android:layout_margin | マージンの指定 | |
android:layout_gravity | 配置方法指定 |