如何将9个补丁图像应用到toggle_btn.xml中?

时间:2019-05-23 13:46:17

标签: android android-button android-togglebutton

我有两个图像,一个是btn_on.9.png,第二个是btn_off.9.png。如您所见,它们是九个补丁图像。

当我将它们直接应用于ImageView时,效果很好。边缘没有破损。

但是,我想在触摸按钮时将按钮应用两个九个补丁,例如打开和关闭。

因此,我这样定义了toggle_btn.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true">
        <bitmap android:src="@drawable/btn_on"/>
        <transition android:autoMirrored="true"/>
    </item>

    <item android:state_checked="false">
        <bitmap android:src="@drawable/btn_off"/>
        <transition android:autoMirrored="true"/>
    </item>
</selector>

并将此xml文件应用于Button视图的背景。但是,它不起作用。我该如何解决这个问题?

0 个答案:

没有答案