Android-theme-demo-example
提供:Dev Guides
Android-テーマのデモの例
次の例は、アプリケーションにテーマを使用する方法を示しています。 デモのために、デフォルトの AppTheme を変更し、デフォルトのテキスト、サイズ、ファミリ、シャドウなどを変更します。 次の手順に従って、シンプルなAndroidアプリケーションの作成から始めましょう-
Step | Description |
---|---|
1 | You will use Eclipse IDE to create an Android application and name it as ThemeDemo under a package com.example.themedemo as explained in the Hello World Example chapter. |
2 | Modify src/MainActivity.java file to add click event listeners and handlers for the two buttons defined. |
3 | Define your style in global style file res/values/style.xml to define custom attributes for a button and change default theme of the application to play with the text. |
4 | Modify the detault content of res/layout/activity_main.xml file to include a set of Android UI controls and make use of the defined style. |
5 | Define required constants in res/values/strings.xml file |
6 | Run the application to launch Android emulator and verify the result of the changes done in the aplication. |
以下は、変更されたメインアクティビティファイル src/com.example.themedemo/MainActivity.java の内容です。 このファイルには、基本的な各ライフサイクルメソッドを含めることができます。
以下は、 res/values/style.xml ファイルのコンテンツで、追加スタイル CustomButtonStyle が定義されます-
以下は res/layout/activity_main.xml ファイルの内容です-
以下は、2つの新しい定数を定義する res/values/strings.xml の内容です-
以下は、 AndroidManifest.xml のデフォルトのコンテンツです。 ここでは、テーマ名を変更しないため、何も変更する必要はありません。 ただし、新しいテーマを新しく定義するか、デフォルトの名前を別の名前で継承する場合は、 AppTheme 名を新しいテーマ名に置き換える必要があります。