Android 5+ remoteviews涟漪效应

van*_*dzi 7 android android-widget android-notifications android-remoteview material-design

是否可能对作为远程视图一部分的按钮产生连锁效应?(使用自定义布局或窗口小部件的通知)

我尝试将按钮背景设置为drawable notification_material_media_action_background:

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="@color/ripple_material_dark"/>
Run Code Online (Sandbox Code Playgroud)

但它没有效果.通知源代码中使用相同的背景,并且通知按钮会产生连锁反应.这是来自Notification source的代码,它创建了动作按钮(具有涟漪效果):

   private RemoteViews More ...generateMediaActionButton(Action action) {
            final boolean tombstone = (action.actionIntent == null);
            RemoteViews button = new RemoteViews(mBuilder.mContext.getPackageName(),
                    R.layout.notification_material_media_action);
            button.setImageViewResource(R.id.action0, action.icon);
            button.setDrawableParameters(R.id.action0, false, -1,
                    0xFFFFFFFF,
                    PorterDuff.Mode.SRC_ATOP, -1);
            if (!tombstone) {
                button.setOnClickPendingIntent(R.id.action0, action.actionIntent);
            }
            button.setContentDescription(R.id.action0, action.title);
            return button;
        }
Run Code Online (Sandbox Code Playgroud)

唯一不同的是这条线:

 button.setDrawableParameters(R.id.action0, false, -1,
                        0xFFFFFFFF,
                        PorterDuff.Mode.SRC_ATOP, -1);
Run Code Online (Sandbox Code Playgroud)

但是这个方法是@hide所以它不能被调用.

知道如何添加涟漪效果吗?谢谢!

A.G*_*A.G 0

对于 ImageButton,在其标签中使用此属性:


 android:background="?android:attr/actionBarItemBackground"

Run Code Online (Sandbox Code Playgroud)