簡體   English   中英

按下狀態時,Android imageButton不會更改顏色

[英]Android imagebutton not change color when state pressed

我的布局中有一個按鈕,按下該按鈕時必須更改圖像。 我有一個選擇器xml。 這是按鈕:

<ImageButton
            android:id="@+id/cwcfwdvcs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:clickable="true"
            android:layout_marginTop="16dp"
            android:background="@drawable/button_add_to_favorites_unactive"
            android:drawable="@drawable/add_to_favorites"
            android:text="Favotites"/>

這是選擇器add_to_favorites.xml:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/button_add_to_favorites_active"
      android:state_checked="true" />
<item android:drawable="@drawable/button_add_to_favorites_unactive" />

您應該像下面的代碼一樣使用按鈕選擇器狀態,即((res / drawable / button.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/button_add_to_favorites_active">

</item>

<item android:state_focused="true" android:drawable="@drawable/button_add_to_favorites_active">

</item>

<item android:drawable="@drawable/button_add_to_favorites_active">        

</item>
</selector>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM