android - 为自定义视图添加了触摸反馈
问题描述
如何在我的自定义视图中添加像涟漪一样的触摸反馈?
我可以检测到触摸事件,但我希望在我的自定义视图被触摸时像涟漪一样简单。那可能吗?
提前致谢。
解决方案
使用这个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();
推荐阅读
- android - 如何实现获取和返回 LifeCycle 的方法
- java - 将 MyObject 的页面映射到 MyObjectDTO 的页面
- javascript - Chart.js 鼠标悬停显示旧图表数据
- django - 如何删除 django-extra-views 中的行?
- oauth - 当您拥有消费者密钥、秘密、令牌和令牌密钥时生成 oauth_Signature 的代码
- reactjs - 在 React Web 应用程序中定义联系我们表单的模型时如何包含 textarea 字段
- ansible - 如何将目录从远程机器复制到本地主机?
- javascript - 有没有办法修改数组中允许的值的标准?
- kubernetes - 如何为 istio 入口网关添加自定义端口?
- ssl - 需要从在线提供商处创建公钥基础设施的指导