android button光晕动画
时间: 2023-07-21 21:41:50 浏览: 44
您可以通过为Button设置一个StateListDrawable来实现Button点击时的光晕效果,具体步骤如下:
1. 在drawable目录下创建一个selector文件,例如:button_selector.xml
```xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/button_normal"/>
</selector>
```
2. 在drawable目录下创建button_pressed.xml和button_normal.xml文件,分别表示按钮点击和未点击时的状态
button_pressed.xml:
```xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#33000000"/>
<corners android:radius="50dp"/>
</shape>
```
button_normal.xml:
```xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#000000"/>
<corners android:radius="50dp"/>
</shape>
```
3. 在布局文件中将Button的background设置为button_selector.xml即可实现光晕效果
```xml
<Button
android:id="@+id/btn_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:background="@drawable/button_selector"/>
```
当按钮被点击时,会显示一个半透明的圆形光晕,效果如下:
![button_pressed](https://img-blog.csdn.net/20180823144913744?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3BhcnRpY2lwYW50X2Jsb2c=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/q/80)