按钮背景的选择器文件

问题描述:

任何人都可以提供选择器文件的背景按钮。按下按钮后,背景图像会改变。我将为按钮的背景设置自定义图像。什么是可绘制文件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

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>