ボタンに画像を配置し、描画可能なソースを使用して、その上にテキストを配置することの両方を組み合わせることが可能かどうか疑問に思っていますか?
現在、これを drawable/red_btn.xml のボタン スタイルとして使用しています。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#ef4444" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#ef4444"
android:endColor="#992f2f"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
そして私のボタン
<Button
android:id="@+id/testButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Income"
android:textSize="15dip"
android:background="@drawable/red_btn"
android:textColor="#fff"
android:textStyle="bold" />
このように見える
このボタンの上に別の .png 画像 (arrow.png) をこのように右に追加したいと思います。
これは可能ですか?
前もって感謝します。 __________________________________________________________________________________________________________________________________________________________
編集
以下のLuksprogのアドバイスに従った後、ドローアブルに「red_btn_normal.xml」ができました
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#ef4444" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#ef4444"
android:endColor="#992f2f"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
およびred_btn_pressed.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true">
<shape>
<solid android:color="#ef4444" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners android:radius="3dp" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
</item>
<item>
<bitmap
android:gravity="right"
android:src="@drawable/arrow" />
</item>
</layer-list>
そして、この「red_btn.xml」のようなボタンを作成します
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/red_btn_pressed" android:state_pressed="true"></item>
<item android:drawable="@drawable/red_btn_normal"></item>
</selector>
そして最後に私のボタン
<Button
android:id="@+id/testButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Income"
android:textSize="15dip"
android:background="@drawable/red_btn"
android:textColor="#fff"
android:textStyle="bold" />
問題は、ボタンをクリックしたときに白い矢印しか表示されず、押されていないときに表示されないことです。コードの何が問題になっていますか? =)