开/关按钮Android的自定义图像 [英] Android custom image on/off button
问题描述
我想创建自定义的ImageButton,但工作像开/关按钮。在点击按钮图像更改为pssed $ P $(直到另一个按钮是pressed)!
I want to create custom ImageButton, but to work like on/ off button. On click on button image to be changed to pressed(until another button is pressed)!
在画面本月按钮上,这一年的时间。
On picture This month button is on , This year off .
我如何创建这样的按钮?
How can I create button like this?
我需要使用,如何?
感谢
推荐答案
谢尔盖Glotov和麦片感谢您的帮助
Sergey Glotov and wheaties thanks for your help
对于每一个我的ImageButton创建默认和pressed国家独立的选择,我在XML中创建的ImageButton:
For every ImageButton I create separate selectors for default and pressed state, I create ImageButton in xml:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/month_button"
android:id="@+id/btnMonth"
android:onClick=ButonMonthClick"/>
和onclick事件所有的ImageButton我编程方式更改背景图片:
And onClick event for all ImageButton I change background image programmatically:
btnWeek.setBackgroundResource(R.drawable.week_pressed);
btnMonth.setBackgroundResource(R.drawable.month_default);
吴丹解决我的问题!
Thant solve my problem!
这篇关于开/关按钮Android的自定义图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!