我想创建一个只包含一个图像的上方或选定的外观。不是以编程方式,而是在 xml 选择器中。对不起,我的英语不好。
试试这个,创建选择器.xml在你的可绘制对象中像这样。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/hover_image" android:state_pressed="true"></item>
<item android:drawable="@drawable/hover_image" android:state_focused="true">/item>
<item android:drawable="@drawable/image_bg"></item>
</selector>
并在布局 xml 中使用
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector"
android:text="@string/notification"
/>