开发者

On click effect on the image button

I have created image buttons instead of normal buttons.On click on the image button I want a click effect as in the normal icon click effect(On click of menu the background of the icon will be y开发者_C百科ellow color) of android phones.Using the following code I code show an image on click of the image button .What changes I have to make further.

 <item android:state_enabled="true"

 android:state_pressed="true"

       android:drawable="@drawable/production_order" /> 

        android:state_enabled="false"

       android:drawable="@drawable/prodution_orders_icon" /> 


Try this code

<?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/camera" />
    <item android:state_pressed="false" android:drawable="@drawable/camera" />
    <item android:state_pressed="true" android:drawable="@drawable/camera_active" />
</selector>


Instead of using directly ImageButton you can use Button with customized background

Here is the sample tutorial.


create xml file using the button image like this

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

add the color folder in values

<?xml version="1.0" encoding="utf-8"?>
<resources>    
   <color name="yellow">#ffffff00</color>  
</resources>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜