可能重複:
how to set image button backgroundimage for different state?安卓:在XML文件中添加一個背景圖像的按鈕
,我有以下聲明按鈕應如何繪製(uabutton.xml):
<?xml version="1.0" encoding="UTF-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<corners
android:radius="3dp" />
<gradient
android:startColor="#000000"
android:endColor="#e9e8e9"
android:angle="270" />
</shape>
</item>
<item android:state_focused="true" >
<shape>
<corners
android:radius="3dp" />
<gradient
android:endColor="#ffffff"
android:startColor="#b9b9b9"
android:angle="270" />
</shape>
</item>
<item android:state_enabled="false">
<shape>
<corners
android:radius="3dp" />
<gradient
android:startColor="#f0aa9f"
android:endColor="#e21f00"
android:angle="270" />
</shape>
</item>
<item>
<shape>
<corners
android:radius="3dp" />
<gradient
android:startColor="#ff8a0e"
android:endColor="#e9e8e9"
android:angle="270" />
</shape>
</item>
</selector>
我的問題是,我想添加一個圖像到每個按鈕的背景。在哪裏,如果有的話,我會在上面添加圖像。
該按鈕被添加到一個RelativeLayout
:
<Button
android:id="@+id/aboutualocationbtn"
android:text="Menu"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/uabutton"/>
邁克其作品prblm你有細whts背景
即uabutton.jpg或文件? –
@Samir如上所述,我想知道將圖像添加到按鈕的位置。 –
你想保持你的漸變,並使用圖片嗎?或者使用圖像文件而不是漸變? – FoamyGuy