Android L——在 View 上播放波纹效果

标签 android android-5.0-lollipop material-design rippledrawable

我试图在某个时间在 View 上(而不是在被触摸的 View 上)播放链式 react (来自 Android L)。 具体来说,当用户成功更改某些文本时,我希望某个 View 播放绿色波纹效果以显示成功。有什么办法可以做到这一点吗?

我尝试将 RippleDrawable 放入动画中,将 RippleDrawable 作为我的“成功 View ”的背景。但是,我不知道如何播放我所描述的波纹动画。

附注我的项目目前只有Android L,所以我不担心向后兼容性。

最佳答案

由于您的掩码只是一个实心矩形,因此您可以将您的波纹 XML 简化为:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight">
    <item android:id="@android:id/mask" android:drawable="@android:color/white" />
    <item android:drawable="@drawable/file_item_selector"/>
</ripple>

您可以通过强制 View 进入和退出按下状态来手动触发链式 react 。

myView.setPressed(true);

// For a quick ripple, you can immediately set false.
myView.setPressed(false);

// Or for a long ripple, you can post to a handler.
myView.postDelayed(new Runnable() {
    public void run() {
        myView.setPressed(false);
    }
}, 500 /* delay in milliseconds */);

关于Android L——在 View 上播放波纹效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25407291/

相关文章:

material-design - 更改 FloatingActionButton 的大小

java - 音频管理器分割为比 Android 提供的更多级别

android - KotterKnife - 某些类不能使用 bindView(R.id.example_id)

android - 你能在Android 5.0中唯一标识一个BLE MAC地址吗?

android - 将其他应用程序固定为设备所有者

android - "android:elevation="在带有编译 API21 的 Lollipop 前设备上不起作用

java - 捕获所有类型的异常编程 Android

android - 更新到 Google Play Services 8.3 后无法解析 GoogleApiClient

android - Material 设计组件按钮全局主题覆盖 splinter

android - 如何制作记分卡类型的布局 CardView?