【发布时间】:2015-02-09 12:20:37
【问题描述】:
我想创建一个 ImageButton 可绘制资源文件,它同时具有图像(不为背景展开)、彩色背景以及右边框和下边框。另外,我希望 state_pressed、state_selected 和默认状态具有不同的设置。
现在我已经成功地为所有状态的图像创建了 xml 资源文件:
<item android:state_selected="true" android:drawable="@drawable/emailselected" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/emailselected" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/emailselected" />
<item android:state_focused="true" android:drawable="@drawable/emailseleted" />
<item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/email" />
我还有背景和右下边框xml资源文件:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/darkgray" />
</shape>
</item>
<item
android:bottom="1dp"
android:right="1dp">
<shape android:shape="rectangle">
<solid android:color="@color/orange" />
</shape>
</item>
<item
android:bottom="1dp"
android:right="1dp">
<shape android:shape="rectangle">
<solid android:color="@color/gray" />
</shape>
</item>
</layer-list>
我想将所有这些合并到一个资源文件中。是否可以? 所以基本上我想:
按下按钮:背景变为蓝色,图标为“email_selected”
按钮被选中:背景变为蓝色,图标为“email_selected”
默认:背景变为灰色,图标为“电子邮件”
我尝试通过在项目中为背景颜色“橙色”和“灰色”添加“android:state”来将这两个资源文件合二为一,但它根本不起作用。
有人可以帮忙吗?
谢谢。
【问题讨论】:
标签: android layout imagebutton