如何在 Android 2.2 中使用 xml 选择器在图像视图中添加选择/覆盖?比如添加不透明度或阿尔法



我想创建一个只包含一个图像的上方或选定的外观。不是以编程方式,而是在 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"
             />

最新更新