2016-03-21 97 views
0

我想在這個線程使用的解決方案:變化的背景圖像時,點擊/集中不起作用

How to change background image of button when clicked/focused

但出於某種原因沒有什麼作品。當按鈕被點擊時,沒有任何變化。

這是activity_main.xml中的按鈕:

<ImageButton 
android:id="@+id/selectContactBtn" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:contentDescription="contacts" 
android:textSize="18sp" 
android:layout_above="@+id/selectMediaBtn" 
android:layout_alignRight="@+id/selectMediaBtn" 
android:layout_alignEnd="@+id/selectMediaBtn" 
android:background="@drawable/select_contact"/> 

這是select_contact.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_pressed="true" android:drawable="@drawable/blocked_mc" /> 
<item android:drawable="@drawable/select_contact" /> //means normal 
</selector> 

這是按鈕的onClick():

Intent intent = new Intent(Intent.ACTION_PICK); 
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE); 
startActivityForResult(intent, ActivityRequestCodes.SELECT_CONTACT); 

我在做什麼錯?

回答

0

好吧,我明白我的錯誤。

我在drawables下命名了xml,它描述了與可繪製圖像本身(select_contact.xml)同名的按下/未按下的行爲。

當我改變它到別的東西時,它就起作用了。

傻,但天色已晚,並且出現:)

希望這可以幫助別人。