我的ImageButton里面有一个图标。 ImageButton和图标背景是透明的。
我想知道如何在图标上添加阴影?阴影应该能够打开/关闭。
如果有人可以帮助中风,我会非常感激。
这是我的imageButton -
<ImageButton
android:id="@+id/icon"
android:layout_width="140dp"
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:layout_weight="0.76"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:onClick="showIconSelector"
android:src="@drawable/icon_0" />
答案 0 :(得分:4)
你应该使用drawable。下面是一个带有渐变,笔触和圆角的矩形示例。使用这些有很多可能性:
这将被放置在您的drawable文件夹中,然后可以像引用任何可绘制资源一样引用。
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="3dp" android:color="#5C5858" />
<corners android:radius="5dp" />
<gradient
android:startColor="#C0C0C0"
android:endColor="#808080"
android:angle="-90" />
</shape>
要使其在On \ Off状态下工作,您需要创建一个选择器,为您想要考虑的每个州使用不同的drawable。