【问题标题】:Ripple and selectableItemBackgroundBorderlessRipple 和 selectableItemBackgroundBorderless
【发布时间】:2015-02-19 22:59:18
【问题描述】:

我正在使用一个显示正常波纹的按钮,但如果我更改为无边框波纹将不起作用。布局内的按钮位置应该在哪里才能始终使这种波纹起作用?它现在位于相对布局内部,并且位于包含图像、按钮和其他内容的其他相对布局之上。

【问题讨论】:

  • 我遇到了类似的问题,我的解决方案是在外部 LinearLayout 中设置android:background="@android:color/transparent",这个 LinearLayout 被 RelativeLayout 包围。这意味着如果我没有在外部布局中放置任何android:background,那么selectableItemBackgroundBorderless 将不起作用。

标签: android background ripple selectable borderless


【解决方案1】:

我制作了一个库,可以轻松解决您的问题

https://github.com/xgc1986/RippleViews

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/btn1"
    android:background:"the color of the button that you want, that important for your case"
    android:text="Default android button"/>

然后用java

View b1 = findViewById(R.id.btn1);

b1.setBackground(RippleDrawableHelper.createRippleDrawable(b1, rippleColor));

这里是文档:https://github.com/xgc1986/RippleViews/blob/master/docs/RippleDrawableHelper.md

编辑

View b1 = findViewById(R.id.btn1);
// this may work
View v2 = findViewById(R.id.parent); //the are where the ripple effect extends
//change the view you send in the function

b1.setBackground(RippleDrawableHelper.createRippleDrawable(v2, rippleColor));

如果这行得通,是因为它为一个视图创建了一个 RippleDrawable,但是你可以将这个 drawable 分配给另一个视图,然后当你按下 b1 视图时,它会显示相对于 v2 的波纹

【讨论】:

  • 但是你的库是做selectableitembackground效果的,我想要无边框效果。 BTW 是一个很棒的库,可以为前棒棒糖设备实现涟漪效应。恭喜!
  • 好的,添加这个功能很容易View b1 = findViewById(R.id.btn1); View v1 = findViewById(R.id.areaOfTheRipple); b1.setBackground(RippleDrawableHelper.createRippleDrawable(v1, rippleColor));
  • 请将它也添加到答案中!
猜你喜欢
  • 2015-08-12
  • 2018-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-24
  • 2013-03-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多