Android(十四):按钮水波效果
作者:互联网
系统自带水波效果
<!-- Resources/drawable/btn_default.xml -->
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1dp" android:color="#67c23a"/>
<solid android:color="#67c23a"/>
<corners android:radius="40dp"/>
<padding android:left="15dp" android:right="15dp"/>
</shape>
<!-- Resources/drawable/btn_ripple.xml -->
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ffffff">
<item android:drawable="@drawable/btn_default" />
</ripple>
<!-- 布局 -->
<Button
android:id="@+id/btn_01"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@drawable/btn_ripple"
android:textColor="#ffffff"
android:text="按钮(扩散组件自带)" />
第三方水波效果
- 安装
<android_by_csharp.Scripts.BtnRippleView
android:id="@+id/btn_02"
android:layout_below="@id/btn_01"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="10dp"
ripple:rv_centered="true">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/btn_default"
android:textColor="#ffffff"
android:text="按钮(第三方依赖)" />
</android_by_csharp.Scripts.BtnRippleView>
// Scripts/BtnRippleView.cs
using Android.Content;
using Android.Graphics;
using Android.Util;
using Com.Andexert.Library;
namespace android_by_csharp.Scripts
{
public class BtnRippleView : RippleView
{
public BtnRippleView(Context context) : base(context) { }
public BtnRippleView(Context context, IAttributeSet attrs): base(context, attrs) { }
public BtnRippleView(Context context, IAttributeSet attrs, int defStyle): base(context, attrs, defStyle) { }
public override void Draw(Canvas canvas)
{
canvas.Save();
base.Draw(canvas);
}
}
}
标签:base,BtnRippleView,attrs,context,按钮,Android,水波,public 来源: https://blog.csdn.net/weixin_43526371/article/details/120650326