Android-style-demo-example
提供:Dev Guides
Android-スタイルデモの例
次の例は、個々の要素にスタイルを使用する方法を示しています。 次の手順に従って、シンプルなAndroidアプリケーションの作成から始めましょう-
Step | Description |
---|---|
1 | You will use Android Studio IDE to create an Android application and name it as myapplication under a package com.example.saira_000.myapplication as explained in the Hello World Example chapter. |
2 | Modify src/MainActivity.java file to add click event listeners and handlers for the button defined |
3 | Define your style in global style file res/values/style.xml to define custom attributes for a button. |
4 | Modify the default content of res/layout/activity_main.xml file to include a set of Android UI controls and make use of the defined style. |
5 | Run the application to launch Android emulator and verify the result of the changes done in the application. |
以下は、変更されたメインアクティビティファイル src/com.example.myapplication/MainActivity.java の内容です。 このファイルには、基本的な各ライフサイクルメソッドを含めることができます。
以下は、 res/values/style.xml ファイルのコンテンツで、追加スタイル CustomButtonStyle が定義されます-
以下は res/layout/activity_main.xml ファイルの内容です-
'_ここにabcはfinddevguidesロゴについて示しています_
以下は、2つの新しい定数を定義する res/values/strings.xml の内容です-
以下は、 AndroidManifest.xml のデフォルトのコンテンツです-
上のボタンをクリックすると、トーストメッセージが表示されます