首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用支持库实现涟漪动画?

如何使用支持库实现涟漪动画?
EN

Stack Overflow用户
提问于 2014-10-28 16:52:59
回答 2查看 155.9K关注 0票数 181

我正在尝试添加一个点击按钮的涟漪动画。我确实喜欢下面的,但它需要minSdKVersion到21。

ripple.xml

代码语言:javascript
复制
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="?android:colorAccent" />
        </shape>
    </item>
</ripple>

按钮

代码语言:javascript
复制
<com.devspark.robototextview.widget.RobotoButton
    android:id="@+id/loginButton"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/ripple"
    android:text="@string/login_button" />

我想让它与设计库向后兼容。

如何做到这一点?

EN

回答 2

Stack Overflow用户

发布于 2018-03-24 02:22:59

有时你有一个自定义的背景,在这种情况下,更好的解决方案是使用android:foreground="?selectableItemBackground"

更新

如果你想要圆角和自定义背景的涟漪效果,你可以使用这个:

background_ripple.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/ripple_color">
<item android:id="@android:id/mask">
    <shape android:shape="rectangle">
        <solid android:color="@android:color/white" />
        <corners android:radius="5dp" />
    </shape>
</item>

<item android:id="@android:id/background">
    <shape android:shape="rectangle">
        <solid android:color="@android:color/white" />
        <corners android:radius="5dp" />
    </shape>
</item>

layout.xml

代码语言:javascript
复制
<Button
    android:id="@+id/btn_play"
    android:background="@drawable/background_ripple"
    app:backgroundTint="@color/colorPrimary"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/play_now" />

我在API >= 21上使用了这个。

票数 21
EN

Stack Overflow用户

发布于 2018-06-15 16:44:35

有时在任何布局或组件上都能用到这一行。

代码语言:javascript
复制
 android:background="?attr/selectableItemBackground"

就像as。

代码语言:javascript
复制
 <RelativeLayout
                android:id="@+id/relative_ticket_checkin"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="?attr/selectableItemBackground">
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26604134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档