采用两个图像在不同的状态下切换按钮 [英] Toggle button using two image on different state
本文介绍了采用两个图像在不同的状态下切换按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用代替的ON / OFF状态的两个图像进行切换按钮。
I need to make a toggle button using two image instead of ON/OFF state.
在关机状态下我设置背景image.But的关文本不能去除,而我使用的背景图片。
At off state i set a background image.But the OFF text can not removed while i use background image.
和我不能点击切换按钮设置在接通状态另一个图像:( 我是新的机器人。 我希望你们帮我把这个问题了。
And i can not set another image on ON state by clicking the toggle button :( I am new in android. I hope you guys help me get out of this problem
推荐答案
做到这一点:
<ToggleButton
android:id="@+id/toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/check" //check.xml
android:layout_margin="10dp"
android:textOn=""
android:textOff=""
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_centerVertical="true"/>
创建check.xml在绘制文件夹
create check.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/selected_image"
android:state_checked="true" />
<!-- When not selected, use white-->
<item android:drawable="@drawable/unselected_image"
android:state_checked="false"/>
</selector>
这篇关于采用两个图像在不同的状态下切换按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文