android ripple水波纹详解
2017-09-22 14:09
260 查看
Ripple是Material Design(材料设计)中的效果;
虽然在5.0的机型上,会自带Ripple点击效果,但是有时候需要自己更改点击效果;
使用Ripple的关键就是在android:background中设置;
使用方法也非常简单,在drawable中创建**.xml文件:
<!--在真是项目中都有自己的主题颜色,Ripple效果的颜色默认是灰色; 可通过android:color 这个属性改变涟漪波浪的颜色--> <ripple xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:color="#ffff0000" tools:targetApi="lollipop">> <!--下面设置颜色没有用,添加item以后会约束水波纹的范围--> <item android:drawable="@android:color/white" /> </ripple>
直接在需要水波纹的按钮上面设置:
<!--直接设置android:background="@drawable/ripple_01"属性即可 记住必须添加android:clickable="true"属性,不然不生效--> <TextView android:layout_width="match_parent" android:layout_height="100dp" android:layout_margin="70dp" android:background="@drawable/ripple_01" android:clickable="true" android:text="不限定边界" />
但是很多按钮需要自定义shape或者设置UI给的图片,在Ripple中设置图片也非常的简单:
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="#FF21272B"> <!--自定义的shape作为背景 也可添加一张图片作为背景--> <item android:drawable="@drawable/tv_bg" /> </ripple>
shape文件tv_ba.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#d5d555" /> <corners android:radius="4dp" /> </shape>
点击打开链接下载源码
相关文章推荐
- Android Ripple的详解
- Android 5.0 MaterialDesign Ripple效果水波纹效果
- Android 5.X之Ripple,Palette的详解
- MPAndroidChart详解
- Android中AsyncTask的使用详解
- Android菜单详解(一)——理解android中的Menu
- 详解Android全局异常的捕获处理
- 【Android进阶】Application对象的详解
- android基础总结篇之九:Intent应用详解 .
- Android开发教程之Fragment定义、创建与使用方法详解【包含Activity通讯,事务执行等】
- Android AsyncTask详解及使用方法
- Android的NDK开发(3)————JNI数据类型的详解
- Android Studio——android中的文件操作详解以及内部存储和外部存储
- Android进阶笔记:AIDL内部实现详解 (二)
- Android环境搭配详解
- Android---SlidingDrawer(滑动式抽屉)详解与实例
- Android开发,ZxMvp框架的引入及使用详解(下)
- Android中的长度单位详解(dp、sp、px、in、pt、mm)
- Android优化详解--For面试