I use a Gallery to display Contacts’s info,on the item view,there has two button which i use selector as their background,now here is the problem,i touch the area out of this two button,this two button will change the background seem like they are all pressed.
here is the gallery item
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#505050"
>
<ImageView
android:id="@+id/phone_contact_image"
android:layout_height="160dip"
android:layout_width="160dip"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dip"
android:src="@drawable/contact_phone_image_1"
/>
<TextView
android:id="@+id/phone_contact_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textSize="25dip"
android:layout_below="@id/phone_contact_image"
android:layout_marginTop="10dip"
android:gravity="center_horizontal"
android:textColor="#FFFFFF"
/>
<TextView
android:id="@+id/phone_contact_numbler"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="25dip"
android:gravity="center_horizontal"
android:layout_below="@id/phone_contact_name"
android:text="@string/contact_phone_numbler"
android:textColor="#FFFFFF"
/>
<Button
android:id="@+id/phone_contact_edit_btn"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/editContact_title_edit"
android:textSize="28dip"
android:background="@drawable/btn_button_bg"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:layout_marginTop="10dip"
android:textColor="#FFFFFF"
android:layout_below="@id/phone_contact_numbler"
/>
<Button
android:id="@+id/phone_contact_call_btn"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/title_call_via"
android:textSize="28dip"
android:background="@drawable/btn_confirm_bg"
android:layout_marginTop="20dip"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:textColor="#FFFFFF"
android:layout_below="@id/phone_contact_edit_btn"
/>
</RelativeLayout>
here is the selector
<?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/btn_button_focus" />
<item android:state_pressed="true" android:drawable="@drawable/btn_button_pressed" />
<item android:drawable="@drawable/btn_button_normal" />
</selector>
you are right. But you didnt mentioned when the state is not pressed or not focused and not selected then what you will do?
Try this:
make a styles.xml file in you res.values folder
and add it.
consider the
@drawable/backgroundbutton.xmlis your selector file and add the below code in that.and finally into your layou file.
set the background of the button to
style/styleNormalButtonhope this will help you