带有边框的涟漪TextView?

时间:2016-03-03 15:04:06

标签: android ripple

我很少有TextView个显示在彼此旁边。目前,我使用android:background="?attr/selectableItemBackground"来触摸涟漪。

现在,我想在没有按下时为TextView添加边框,并在触摸TextView时产生波纹。我该怎么做?

1 个答案:

答案 0 :(得分:16)

基于Styling Android blog post

  

我们可以限制波纹动画边界的另一种方法是   实际上定义了一个可绘制为儿童的形状

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white" />
            <stroke
                android:color="@color/card_set_bg_color"
                android:width="1dp" />
        </shape>
    </item>
</ripple>  

此处需要<solid> <shape>来呈现涟漪。如果设置为transparent或省略,则纹波不会渲染。涟漪需要坚实的背景来渲染。 TextView没有背景颜色,因此我们需要指定<solid>