带有可绘制xml阴影的Android按钮

时间:2016-07-15 14:12:57

标签: android xml xml-drawable

我想创建一个drawable并将其用作我的按钮的背景。 阴影的高度必须是18dip。见图。

This should be described in drawable xml

我已经尝试过这种方式,但它不起作用:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false">
        <layer-list>
            <item android:gravity="bottom">
                <bitmap android:src="@drawable/shadow9path"/> // This is a 9-path picture
            </item>
            <item android:gravity="bottom"
                  android:bottom="18dp">
                <shape android:shape="rectangle">
                    <size android:height="@dimen/..." />
                    <corners android:radius="@dimen/..." />
                    <solid android:color="@color/..." />
                </shape>
            </item>
        </layer-list>
    </item>
...
</selector>

修改 阴影应该只在按钮的底部。所以按钮不应该带阴影圆角。我需要像复合视图这样的东西,它由按钮和它下面的阴影组成。

2 个答案:

答案 0 :(得分:1)

试试这个

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <layer-list>
        <item android:right="5dp" android:top="5dp">
            <shape>
                <corners android:radius="3dp" />
                <solid android:color="#D6D6D6" />
            </shape>
        </item>
        <item android:bottom="2dp" android:left="2dp">
            <shape>
                <gradient android:angle="270" 
                    android:endColor="#E2E2E2" android:startColor="#BABABA" />
                <stroke android:width="1dp" android:color="#BABABA" />
                <corners android:radius="4dp" />
                <padding android:bottom="10dp" android:left="10dp" 
                    android:right="10dp" android:top="10dp" />
            </shape>
        </item>
</layer-list>

</item>

</selector>

答案 1 :(得分:0)

这项工作形成了我,尝试:

   <!DOCTYPE html>
   <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
     <body>
    <h1>Hello World!</h1>

    <form action="myservlet"  method="GET"    >

        First name:<br> 
        <input type="text" name="firstname"/> 
        <br> 
        Last name:
        <br> 
        <input type="text" name="lastname" /> 
        <br><br> 
        <input type="submit" value="Submit"/> 
      </form>
      </body>
      </html>