【问题标题】:How to create shadow drawable for button?如何为按钮创建可绘制的阴影?
【发布时间】:2020-01-31 12:04:36
【问题描述】:

我尝试过使用 9-patch drawable 作为图层列表,也使用了渐变,但在这两种情况下我都无法获得准确的结果,我们如何设计阴影 drawable?

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:left="@dimen/_10sdp"
        android:right="@dimen/_10sdp">
        <shape android:shape="rectangle">

            <corners
                android:bottomLeftRadius="@dimen/_4sdp"
                android:bottomRightRadius="@dimen/_4sdp"
                android:topLeftRadius="@dimen/_50sdp"
                android:topRightRadius="50sp"
                />

            <gradient
                android:angle="90"
                android:startColor="#0D4c4c4c"
                android:endColor="#0D4c4c4c"
                android:centerColor="#334c4c4c"
                android:type="linear" />

        </shape>

    </item>
    <item android:bottom="@dimen/_7sdp">
        <shape android:shape="rectangle">
            <solid android:color="#b9b9b9" />
        </shape>
    </item>
</layer-list>

【问题讨论】:

  • 你在尝试卡片视图吗?
  • 不,我想在 Button 中使用它。
  • 是的,但您可以在卡片视图中添加按钮。
  • 实际上我已经创建了样式,我想应用于整个应用程序而不是更改不同的 .xml。
  • 你试试我的答案吗?

标签: android gradient drawable nine-patch


【解决方案1】:

您可以在您的 xml文件:android:elevation="6dp"

【讨论】:

    【解决方案2】:

    请试试下面的drawable

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item>
            <shape android:shape="rectangle">
                <gradient
                    android:angle="180"
                    android:startColor="#0D4c4c4c"
                    android:endColor="#0D4c4c4c"
                    android:centerColor="#334c4c4c"
                    android:type="linear" />
    
            </shape>
    
        </item>
        <item android:bottom="@dimen/_10sdp">
            <shape android:shape="rectangle">
                <solid android:color="#b9b9b9" />
            </shape>
        </item>
    </layer-list>
    

    希望对你有帮助!

    谢谢。

    【讨论】:

      【解决方案3】:
         <?xml version="1.0" encoding="utf-8"?>
      <selector xmlns:android="http://schemas.android.com/apk/res/android">
          <item android:state_pressed="false">
              <layer-list>
                  <!-- SHADOW -->
                  <item>
                      <shape>
                          <solid android:color="@color/red_400"/>
      
      
                      </shape>
                  </item>
      
                  <item
                      android:bottom="5px"
                      >
                      <shape>
                          <padding android:bottom="5dp"/>
                          <gradient
                              android:startColor="#1c4985"
                              android:endColor="#163969"
                              android:angle="270" />
                          <corners
                              android:radius="19dp"/>
                          <padding
                              android:left="10dp"
                              android:top="10dp"
                              android:right="5dp"
                              android:bottom="10dp"/>
                      </shape>
                  </item>
              </layer-list>
          </item>
      </selector>
      

      试试这个

      【讨论】:

      • 其实我不想在drawable上做动画,我对如何设计上面提到的按钮有疑问。
      猜你喜欢
      • 1970-01-01
      • 2014-12-19
      • 1970-01-01
      • 1970-01-01
      • 2012-09-20
      • 2013-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多