MBM*_*BMJ 98 android togglebutton
我需要使用两个图像而不是ON/OFF状态来设置切换按钮.
在关闭状态下我设置了背景图像.但是当我使用背景图像时,无法删除OFF文本.
而且我无法通过点击切换按钮在ON状态下设置另一个图像:(我是android的新手.我希望你们帮助我摆脱这个问题
Aka*_*shG 214
做这个:
<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"/>
在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>
Mis*_*een 46
AkashG的解决方案对我不起作用.当我将check.xml设置为背景时,它只是在垂直方向上划线.要解决此问题,您应该将check.xml设置为"android:button"属性:
<ToggleButton 
    android:id="@+id/toggle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:button="@drawable/check"   //check.xml
    android:background="@null"/>
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>
| 归档时间: | 
 | 
| 查看次数: | 101920 次 | 
| 最近记录: |