单击图像按钮上的效果

时间:2011-09-29 04:28:43

标签: android imagebutton

我已经创建了图像按钮而不是普通按钮。点击图像按钮我想要一个点击效果,就像Android手机中的普通图标点击效果(点击菜单图标的背景将是黄色)一样。使用下面的代码我代码在点击图像按钮时显示图像。我需要做些什么改变。

 <item android:state_enabled="true"

 android:state_pressed="true"

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

        android:state_enabled="false"

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

3 个答案:

答案 0 :(得分:2)

试试此代码

<?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>

答案 1 :(得分:1)

您可以使用具有自定义背景的Button

,而不是直接使用ImageButton

以下是示例tutorial

答案 2 :(得分:0)

使用像这样的按钮图像创建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="@color/transparent" />
<item 
  android:drawable="@drawable/closebutton" />
</selector>

在值

中添加颜色文件夹
<?xml version="1.0" encoding="utf-8"?>
<resources>    
   <color name="yellow">#ffffff00</color>  
</resources>
相关问题