【问题标题】:Android - Set a Drawable to multiple buttonsAndroid - 将 Drawable 设置为多个按钮
【发布时间】:2018-01-24 14:29:01
【问题描述】:

将相同的Drawable设置为多个按钮/视图作为背景(使用setBackground(Drawable)会出现波纹效果问题,当我单击按钮A时,会显示按钮B的波纹效果。

注意:我测试了mutate(),但没有任何效果

【问题讨论】:

  • 你能在两个按钮上都设置点击监听器并确保两个按钮都没有收到点击吗?

标签: android android-drawable rippledrawable


【解决方案1】:

试试 Drawable newDrawable = oldDrawable.getConstantState().newDrawable().mutate();

【讨论】:

  • 它就像一个魅力!你有什么解释它为什么起作用吗?
  • 是的,因为 newDrawable() 对原始可绘制对象进行深层复制。
猜你喜欢
  • 2015-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
  • 2019-12-29
  • 1970-01-01
  • 2020-10-31
相关资源
最近更新 更多