【问题标题】:Android Lollipop - ripple effect in notificationAndroid Lollipop - 通知中的涟漪效应
【发布时间】:2015-03-23 16:47:54
【问题描述】:

我想在 Android Lollipop 的通知中为 ImageView / ImageButton 添加波纹效果。我看到这在 Google Play 音乐上是可能的。但是,我在其他视图中使用的解决方案不适用于通知。

我在 drawable-v21 中创建了 RippleDrawable

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="#33000000">
</ripple>

并将这个drawable设置为ImageView的背景

<ImageView android:id="@+id/notification_play_button"
           tools:src="@drawable/av_play_over_video"
           android:layout_width="32dp"
           android:layout_height="32dp"
           android:background="@drawable/button_selector_semi_black"
            />

但它根本不起作用。你有什么想法如何实现这个效果?

【问题讨论】:

  • 我怀疑您想要一个在单击按钮时应用波纹的&lt;selector&gt; (StateListDrawable)。
  • @CommonsWare 我试图将&lt;selector&gt;&lt;item android:state_pressed="true" android:drawable="@drawable/button_selector_semi_black"&gt; 相加,其中button_selector_semi_black 是我的涟漪,没有任何效果:( 可能为时已晚,而且我失明了:/
  • 如果您在模拟器上进行测试,AFAIK 您需要打开主机 GPU 模式才能看到效果。我不能在我的 Ubuntu 设置上使用主机 GPU 模式(虽然我最近没有尝试过,所以也许他们修复了这个错误),但要看到涟漪,我必须在 Android 5.0 硬件上进行测试。
  • 我正在使用 Android 5.0.0 和 HTC One GPE 测试 Genymotion 和 5.0.1 ;/
  • 棉花糖中的相同。您是否在问题跟踪器中提出了错误报告?

标签: android android-notifications android-5.0-lollipop rippledrawable


【解决方案1】:

我猜你使用“RemoteViews”来定制你的通知布局。

尝试添加 "android:background="@android:color/transparent"

在您自定义布局的视图组中。

【讨论】:

  • 有了这个,波纹起作用了,但我在一些三星手机(如 S6)中发现了一个非常丑陋的错误。如果你使用它,通知实际上是透明的(是的,你可以看到它背后的东西)。这可能只是三星的一个错误,但它仍然很烦人......没有设置背景在所有地方都可以工作,但是按钮的波纹不可见。
  • 这不会在 RemoteViews 中产生涟漪效果。
猜你喜欢
  • 1970-01-01
  • 2020-05-30
  • 2015-07-03
  • 1970-01-01
  • 2019-12-07
  • 2016-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多