2013-10-05 2 views
0

버튼이 있습니다. 버튼을 클릭하면 버튼이 바뀌 었습니다. 모든 것이 괜찮은 것 같지만 버튼을 클릭하면 배경 버튼이 한 순간 (배경을 선택하는 동안) 변경된 다음 배경 버튼이 첫 번째 배경색이됩니다. (내 문제는 무엇입니까?선택기를 통해 버튼의 배경을 변경

contact_selector.xml :

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

activity_test.xml :

<?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"> 
<FrameLayout 
    android:id="@+id/frame" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/white" 
    android:layout_above="@id/btn"></FrameLayout> 
<Button 
    android:id="@+id/btn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/contact_selector" 
    android:layout_alignParentBottom="true"/> 
</RelativeLayout> 

감사합니다 ...

답변

0
// try this 
<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@drawable/contactpress" android:state_pressed="true"></item> 
    <item android:drawable="@drawable/contactpress" android:state_focused="true"></item> 
    <item android:drawable="@drawable/contact" android:state_enabled="true" android:state_focused="false" android:state_pressed="false"></item> 
    <item android:drawable="@drawable/contactpress" android:state_enabled="false"></item> 

</selector> 
관련 문제