Android-button-control
Android-ボタン制御
'_ボタンは、ユーザーがアクションを実行するために押したりクリックしたりできるプッシュボタンです。_
ボタンの属性
以下は、ボタンコントロールに関連する重要な属性です。 属性の完全なリストと、これらの属性を実行時に変更するために使用できる関連メソッドについては、Androidの公式ドキュメントを確認してください。
Sr.No | Attribute & Description |
---|---|
1 |
android:autoText 設定されている場合、このTextViewにテキスト入力メソッドがあり、いくつかの一般的なスペルエラーを自動的に修正することを指定します。 |
2 |
android:drawableBottom これは、テキストの下に描画されるドロアブルです。 |
3 |
android:drawableRight これは、テキストの右側に描画されるドロアブルです。 |
4 |
android:editable 設定されている場合、このTextViewに入力メソッドがあることを指定します。 |
5 |
android:text これは表示するテキストです。 |
Attribute | Description |
---|---|
1 |
android:background これは背景として使用するドロアブルです。 |
2 |
android:contentDescription これは、ビューのコンテンツを簡単に説明するテキストを定義します。 |
3 |
android:id これは、このビューの識別子名を提供します。 |
4 |
android:onClick これは、ビューがクリックされたときに呼び出すこのビューのコンテキスト内のメソッドの名前です。 |
5 |
android:visibility これにより、ビューの初期可視性が制御されます。 |
例
この例では、簡単な手順で、リニアレイアウトとボタンを使用して独自の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 a click event. |
3 | Modify the default content of res/layout/activity_main.xml file to include Android UI control. |
4 | No need to declare default string constants at string.xml, Android studio takes care of default string constants. |
5 | Run the application to launch Android emulator and verify the result of the changes done in the application. |
以下は、変更されたメインアクティビティファイル src/MainActivity.java の内容です。 このファイルには、基本的な各ライフサイクルメソッドを含めることができます。
以下は res/layout/activity_main.xml ファイルの内容です-
以下は、これらの新しい定数を定義する res/values/strings.xml の内容です-
以下は、 AndroidManifest.xml のデフォルトのコンテンツです-
ボタンをクリックすると、次の画面が表示されます-
運動
プログラミング時にボタンの異なる属性を使用して上記の例を試して、ボタンの外観を変えることをお勧めします。 編集可能にし、フォントの色、フォントファミリ、幅、textSizeなどに変更して、結果を確認してください。 1つのアクティビティで複数のButtonコントロールを使用して上記の例を試すこともできます。