2012-04-16 46 views
1

任何人都可以提供選擇器文件的背景按鈕。按下按鈕後,背景圖像會改變。我將爲按鈕的背景設置自定義圖像。什麼是可繪製文件listbackground的內容?按鈕背景的選擇器文件

<Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="40dp" 
     android:text="Button 1" 
     android:background="@drawable/listbackground"/> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignRight="@+id/button1" 
     android:layout_below="@+id/button1" 
     android:layout_marginTop="37dp" 
     android:text="Button 2" 
     android:background="@drawable/listbackground"/> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignRight="@+id/button2" 
     android:layout_centerVertical="true" 
     android:text="Button 3" 
     android:background="@drawable/listbackground"/> 

    <Button 
     android:id="@+id/button4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/button3" 
     android:layout_below="@+id/button3" 
     android:layout_marginTop="48dp" 
     android:text="Button 4" 
     android:background="@drawable/listbackground"/> 

</RelativeLayout> 
+1

你有什麼問題嗎? – Raptor 2013-10-31 02:33:55

+0

@ShivanRaptor我想要選擇器文件的代碼作爲按鈕的背景。當我們按下按鈕時,背景圖像會改變。這是一個自定義圖像。 – 2013-10-31 04:46:54

+0

@ShivanRaptor我認爲這個問題現在很清楚,現在的問題還不清楚? – 2013-11-06 11:09:37

回答

3

listbackground.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:state_focused="true" android:drawable="@drawable/mainfocussed"></item> 
    <item android:state_pressed="true" android:drawable="@drawable/mainpressed"></item> 
    <item android:drawable="@drawable/main"></item> 

</selector>