我有两个图像,一个是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
视图的背景。但是,它不起作用。我该如何解决这个问题?