Touch Feedback(触摸反馈)
例子:水波纹效果
水波纹效果是5.0+自带的。
<Button
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="hello_world" />
<Button
android:layout_width="wrap_content"
android:layout_height="100dp"
android:background="?attr/selectableItemBackground"
android:text="hello_world" />
<Button
android:layout_width="wrap_content"
android:layout_height="100dp"
android:background="?attr/selectableItemBackgroundBorderless"//没有边界,圆形
android:text="hello_world" />
Button背景颜色设置不同的背景。
android:background=”?attr/selectableItemBackground”
android:background=”?attr/selectableItemBackgroundBorderless”//没有边界,圆形
可以修改背景颜色和水波纹的颜色:
value-v21/styles.xml
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorControlHighlight">@color/colorPrimary_pink</item>
<item name="colorButtonNormal">@color/material_blue_grey_800</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
Activity或者Application的android:theme="@style/AppTheme"
这样就可以改变5.0以上水波纹的颜色
最好使用AppcompatActivity
Reveal Effect(揭露效果)
例子:Activity的揭露出现的效果。
ViewAnimationUtil工具类
//圆形水波纹揭露效果
ViewAnimationUtils.createCircularReveal(
view, //作用在哪个View上面
centerX, centerY, //扩散的中心点
startRadius, //开始扩散初始半径
endRadius)//扩散结束半径
// 中心扩散的揭露效果
final Animator circularReveal = ViewAnimationUtils.createCircularReveal(bt1, bt1.getWidth() / 2, bt1.getHeight() / 2, 0, bt1.getHeight());
circularReveal.setDuration(500);
circularReveal.setInterpolator(new AccelerateInterpolator());
circularReveal.start();
// 从左上角开始的揭露效果
Animator animator = ViewAnimationUtils.createCircularReveal(bt2, 0, 0, 0, (float)Math.hypot(bt2.getWidth(), bt2.getHeight()));
animator.setDuration(1000);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();