android涟漪动画,如何添加涟漪效果并在android中的按钮上有自定义背景?

  • Post author:
  • Post category:其他


请告诉我如何实现这两个目标,我已经解决了很多已经存在的问题,但他们并没有专门处理我的问题.

我想在我的按钮上产生涟漪效果,并且它应该是圆形的并且具有背景颜色.此外,我应该能够控制涟漪效果的颜色.

我尝试了下面列出的一些东西.

第一种方法:我尝试在< Button>中设置style =“@ style / AppTheme”.标签.这给了我涟漪效果和背景颜色(在样式中使用< item name =“colorButtonNormal”>#500347< / item>)但是按钮没有舍入.

所以为了实现圆形,我在< Button>中给了android:background =“@ drawable / button_bg”.标签.这使得按钮变圆并且还实现了背景颜色,但是波纹效果消失了.

第二种方法:我尝试了使用选择器.

1.创建了button_background.xml

android:state_focused=”true”

android:drawable=”@drawable/button_bg”/>

android:state_pressed=”true”

android:drawable=”@drawable/ripple_effect”/>

android:drawable=”@drawable/ripple_effect”/>

> button_bg.xml中按钮的圆形背景:

android:color=”#500347″ />

android:radius=”10dip” />

android:bottom=”0dip”

android:left=”0dip”

android:right=”0dip”

android:top=”0dip” />

> ripple_effet.xml:

xmlns:tools=”http://schemas.android.com/tools”

android:color=”@android:color/holo_green_dark”

tools:targetApi=”lollipop”>

>在< Button>中标签

机器人:背景= “@绘制/ button_bg”

使用此方法按钮在按下时会变为白色,返回背景颜色.

请告诉我怎么做.