基于安卓5.0水波纹效果制作及自定义水波纹颜色

安卓5.0以后很多ui效果的改进都是为提高用户体验,其中水波纹效果是5.0以后是在交互方式中做的特殊处理
接下来学习一下水波纹的简单使用及水波纹颜色的自定义。

首先布局文件中给控件设置为可点击,及背景的添加
   
   
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
 
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:background="?android:attr/selectableItemBackgroundBorderless"//此背景为安卓中默认颜色
android:clickable="true"
android:text="默认水波纹颜色:无边界效果" />
 
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:background="?android:attr/selectableItemBackground"//此背景为安卓中默认颜色
android:clickable="true"
android:gravity="center"
android:text="默认水波纹颜色:无界效果" />
 
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:background="@drawable/ripple_item_background_normal"
android:clickable="true"
android:gravity="center"
android:text="自定义水波纹颜色:无边界效果" />
 
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:background="@drawable/ripple_item_background_select"
android:clickable="true"
android:gravity="center"
android:text="自定义水波纹颜色:有边界效果" />
</LinearLayout>

ripple_item_background_normal.xml文件的定义
   
   
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/colorAccent" />

ripple_item_background_select.xml文件的定义
   
   
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/colorAccent">
<item android:drawable="@color/colorPrimary" />
</ripple>

通过2种情况的xml文件会发现在定义 drawable为控件的背景颜色,在没有定义的情况下为默认无边界效果
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值