按钮背景的选择器文件



任何人都可以为按钮的背景提供选择器文件吗?按下按钮时,背景图像会发生变化。我将为按钮的背景设置自定义图像。可绘制文件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>

> 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>

最新更新