为ImageButton添加阴影以绘制

时间:2015-07-31 15:17:32

标签: android android-imagebutton

我有一个像这样设计的图像按钮

 <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/plusOneButton"
            android:layout_marginBottom="5dp"
            android:src="@drawable/thinking"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:background="@drawable/button_border"
            />

button_border xml看起来像这样。

  <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <stroke
        android:width="30dp"
        android:color="#ff000000" />
    <padding
        android:left="1dp"
        android:top="1dp"
        android:right="1dp"
        android:bottom="1dp" />

</shape>

因此,图像被一个盒子包围,它看起来不像一个可按下的按钮。如何为其添加阴影以使其看起来像一个按钮?请帮忙,我是android的新手。我不想添加涟漪作为我的应用程序中的最小api级别是14.

1 个答案:

答案 0 :(得分:0)

你可以使用Layer-List,你可以添加两个或多个形状以实现阴影,然后你需要创建一个drawable选择器来设置在每个状态下使用的drawable,如focus,press ......等这些链接将帮助您检查它们:

层列表

http://nick.perfectedz.com/android-layerlist-tip/

选择

http://www.compiletimeerror.com/2014/03/android-button-selector-tutorial-with.html

我希望这会对你有所帮助:)。

相关问题