棒棒糖视图的涟漪效应

Zai*_*far 20 android material-design

我一直在为Lollipop(API 21)开发一个应用程序.

当我将Button颜色更改为某些内容时,涟漪效果不起作用.

我找到了一些第三方库用于涟漪效应,但我想用标准API做到这一点.

这个答案也没有帮助.

XML:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button"
    android:layout_below="@+id/textView"
    android:background="@android:color/holo_blue_bright"
    android:layout_alignParentStart="true"
    android:layout_marginTop="76dp"
   />
Run Code Online (Sandbox Code Playgroud)

Flo*_*ern 31

您必须将按钮的背景设置为RippleDrawable,您可以使用XML定义它.(我会说出来holo_blue_ripple.xml)

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@android:color/white"> <!-- ripple color -->

    <item android:drawable="@android:color/holo_blue_bright"/> <!-- normal color -->

</ripple>
Run Code Online (Sandbox Code Playgroud)

然后用它来引用它android:background="@drawable/holo_blue_ripple".

  • 如何处理Pre-Lollipop版本? (8认同)
  • 我想出了解决方案.这是:`<ripple xmlns:android ="http://schemas.android.com/apk/res/android"android:color ="@ android:color/holo_blue_bright"> <! - 涟漪色 - > <item> <shape android:shape ="rectangle"> <corner android:radius ="5dp"/> </ shape> </ item> <item android:drawable ="@ android:color/holo_blue_dark"/> <! - 正常颜色 - > </ ripple>` (3认同)

kip*_*ip2 27

试试这个:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="?attr/selectableItemBackground"
    ...
 />
Run Code Online (Sandbox Code Playgroud)

基于本教程官方文档


Mea*_*man 7

?attr/selectableItemBackgroundBorderless可以用于圆形波纹效果.