【问题标题】:Keep ripple within stroke保持笔划内的波纹
【发布时间】:2015-08-24 01:58:32
【问题描述】:

我正在尝试为带有笔划的Button 创建一个ripple 背景drawable

这是我目前所拥有的:

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#336699">

    <item>
        <shape android:shape="rectangle">

            <solid android:color="#998811" />

            <stroke
                android:width="2dp"
                android:color="#119988" />

        </shape>
    </item>
</ripple>

但使用此解决方案,波纹与我的笔划重叠。
我只想要笔划内的ripple,我该怎么做?

【问题讨论】:

    标签: android rippledrawable


    【解决方案1】:

    根据the documentation,您添加另一个 ID 为 @android:id/mask 的项目 - 这将限制涟漪的去向。您可以将其设置为插入,如下所示:

    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="#336699">
    
        <item>
            <shape android:shape="rectangle">
    
                <solid android:color="#998811" />
    
                <stroke
                    android:width="2dp"
                    android:color="#119988" />
    
            </shape>
        </item>
    
        <item android:id="@android:id/mask">
            <inset android:insetBottom="2dp"
                   android:insetLeft="2dp" 
                   android:insetRight="2dp"
                   android:insetTop="2dp">
                <shape android:shape="rectangle">
                    <!-- Color doesn't matter -->
                    <solid android:color="@android:color/white"/>
                </shape>
            </inset>
        </item>
    </ripple>
    

    【讨论】:

      猜你喜欢
      • 2020-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-07
      • 1970-01-01
      • 2011-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多