MaterialDesign的触摸反馈和揭露效果

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或者Applicationandroid: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();
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值