关于水波纹的添加已经定义颜色以及低版本兼容,水波纹颜色
投稿于 被查看 4373 次 评论:287
关于水波纹的添加已经定义颜色以及低版本兼容,水波纹颜色
项目需求 要求在控件上添加点击效果,ok 我本能的想到 我应该是写个选择器,写完之后 产品说应该是水波纹效果,其实在android的版本差异上5.0 之下是没有水波纹的 这个东西是在5.0 及以后才添加的,所以我觉得没必要非加成水波纹,当然在5.0上做成水波纹也可以的,所以我针对系统区分了一下:
5.0 中添加了 波纹效果也就是(ripple)
理论上说 只要使用了Material主题 水波纹点击效果就会应用在所有控件上 5.0上 是用了AppCompat替代了
- <resources>
- <!-- your app's theme inherits from the Material theme -->
- <style name="AppTheme" parent="android:Theme.Material">
- <!-- theme customizations -->
- </style>
- </resources>
- <resources>
- <!-- Base application theme. -->
- <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
- <!-- Customize your theme here. -->
- <item name="colorPrimary">@color/colorPrimary</item>
- <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
- <item name="colorAccent">@color/colorAccent</item>
- </style>
- </resources>
系统自带的有两种一种无界 一种有界 只要设置background就可以了
有界:android:background="?android:attr/selectableItemBackground"
无界:android:background="?android:attr/selectableItemBackgroundBorderless" 安装最低版本在21 所以target在21
然而这并不能满足我的需求所以只能另谋蹊径了
自定义 5.0 下用selecter 以上用ripple
因为ripple 在5.0以上才有所以我在5.0上使用drawable-v21就是在drawable同级目录下新建一个
在5.0 一下用drawable中的资源
为了避免引用失败这种低级错误 在drawable 与 drawable-v21中的名称应该相同哦 就叫click_shape_bg 因为定义了圆角所以带个shape
drawable
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false"> <shape android:shape="rectangle"> <corners android:radius="5dp" /> <solid android:color="@color/colorPrimary" /> </shape> </item> <item android:state_pressed="true"> <shape android:shape="rectangle"> <corners android:radius="5dp" /> <solid android:color="@color/colorPrimaryDark" /> </shape> </item> </selector>drawable-v21
<?xml version="1.0" encoding="utf-8"?> <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/colorPrimaryDark"> <!--上面的颜色是水波纹的颜色--> <!--去掉此item内容就是无界效果--> <item> <!--背景色设置圆角等操作--> <shape android:shape="rectangle"> <solid android:color="@color/colorPrimary"/> <corners android:radius="5dp"></corners> </shape> </item> </ripple>应该要上个效果的 我想想怎么传一个视频啊
下载地址点击打开链接
相关文章
- 暂无相关文章
用户评论