I need to make a toggle button using two image instead of ON/OFF state.

我需要使用两个图像而不是ON / OFF状态来设置切换按钮。

At off state i set a background image.But the OFF text can not removed while i use background image.

在关闭状态下我设置了背景图像。但是当我使用背景图像时,无法删除OFF文本。

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

而且我无法通过点击切换按钮在ON状态下设置另一个图像:(我是android的新手。我希望你们能帮助我摆脱这个问题

3 个解决方案

#1


201

Do this:

做这个:

<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"/>

create check.xml in drawable folder

在drawable文件夹中创建check.xml

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

更多相关文章

  1. 如何让按钮共享android中对话框宽度的一半?
  2. 安卓,如何让两个按钮相邻,宽度相同
  3. 按下子活动后退按钮后,Android主要活动的元素不响应
  4. POST json和图像到服务器android
  5. JSP页面中有一个按钮 点击之后执行JAVA文件
  6. Java实现图像对比类
  7. 为可执行文件夹提供自定义图像
  8. 在扑克游戏中显示卡片的图像
  9. 不幸的是,在声明按钮时,模拟器中出现了错误

随机推荐

  1. Python note1(语言语义)
  2. 使用python实现菱形的两种方法
  3. javascript类定义与对象的性能
  4. Win7 64为Sublime Text3 配置python3的开
  5. 一个在线音乐软件的故事(三、音乐从哪里来
  6. ArcGIS for Service中JavaScript预览在内
  7. 使用python为jpegs创建缩略图
  8. 【JavaScript】AJAX总结(异步JavaScript和
  9. typeescript:在数字上使用parseInt()时出
  10. Bottle 框架源码学习 四