我知道这里有很多此类问题,但我真的不知道我的代码不起作用的原因。
我正在尝试制作一个具有三种状态的按钮:正常、按下和释放。当我说发布时,我的意思是我想让它像一个toogle按钮一样,状态为active
和not active
。
当我释放按钮时,它会返回到默认状态。我想通过单击更改图像,因为 checkButton 有效。
我试过这个:
http://blog.androgames.net/40/custom-button-style-and-theme/
http://www.gersic.com/blog.php?id=56
Android: How to Create a Custom button widget
http://techdroid.kbeanie.com/2010/03/custom-buttons-on-android.html
custom_buttom.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/focussed" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/focussedandpressed" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/pressed" />
<item android:drawable="@drawable/default" />
</selector>
布局.xml:
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/menu"
android:layout_weight="1" android:background="@drawable/custom_button"></Button>
最佳答案
您正在使用 android:state_focused
和 android:state_pressed
。
关于java - 如何在android上制作一个按下和释放的自定义按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6619070/