首页 > 解决方案 > 为自定义视图添加了触摸反馈

问题描述

如何在我的自定义视图中添加像涟漪一样的触摸反馈?

我可以检测到触摸事件,但我希望在我的自定义视图被触摸时像涟漪一样简单。那可能吗?

提前致谢。

标签: androidandroid-custom-viewtouch-feedback

解决方案


使用这个compile 'com.balysv:material-ripple:1.0.2',把你的自定义小部件放在里面MaterialRippleLayout在这里

  <com.balysv.materialripple.MaterialRippleLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                app:mrl_rippleAlpha="0.3"
                android:layout_weight="2"
                app:mrl_rippleColor="#80FF5722"
                app:mrl_rippleDimension="10dp"
                app:mrl_rippleHover="true"
                app:mrl_rippleOverlay="true">
            <com.your.custome.view
               />
            </com.balysv.materialripple.MaterialRippleLayout>

您也可以以编程方式使用它

MaterialRippleLayout.on(view)
           .rippleColor(Color.BLACK)
           .create();

推荐阅读