[アンドロイド] ボタンのアンドロイドの色 – ボタンの色のアンドロイド
ボタンを使用することができるの色を設定します アンドロイド:背景=”カラーコード” ボタンの
最高経営責任者(CEO: アンドロイド:背景=”#F00″ => 私赤.
しかし、我々はボタンをクリックしてこのように、ボタンがクリックされるべきではないように見えた反応は表示されません.
この問題を解決するには、次の操作を行います:
ステップ 1: 以下の内容で、フォルダのres /値のcolor.xmlファイルを作成します。 (このファイルは、使用する色を定義します):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#f00</color> <!-- Màu đỏ -->
<color name="blue">#00f</color> <!-- Màu xanh da trời -->
</resources>
ステップ 2: フォルダbutton_color.xmlの解像度/描画可能にファイルを作成します。 (このフォルダなしで、新しいを作成することができます) コンテンツを持ちます (このファイルには、ボタンの色を作成します。):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/red"
android:state_pressed="true"/> <!-- Hiện màu đỏ khi ấn vào nút -->
<item android:drawable="@color/blue"
android:state_pressed="false"/> <!-- Hiện màu xanh da trời khi không nhấn nút -->
</selector>
ステップ 3: コマンドを使用します。 アンドロイド:背景=”@描画可能/ button_color” ファイル作成button_colorで色を設定します
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="My Button"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="20dp">
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
android:textSize="30sp"
android:background="@drawable/button_color"/> <!-- Đặt màu trong file button_color -->
</LinearLayout>
</LinearLayout>




最近のコメント