View点击涟漪效果
16lz
2021-01-26
方法1:
在大多数情况下,在布局XML文件中使用如下的方法去指定视图的背景:
?android:attr/selectableItemBackground (有界波纹)
?android:attr/selectableItemBackgroundBorderless (无界波纹)
注意:selectableItemBackgroundBorderless是API级别21上的新属性。
要更改默认的触摸反馈颜色,使用主题的android:colorControlHighlight属性
例如:
android:id="@+id/compare"
android:layout_width="@dimen/menu_icon_width"
android:layout_height="@dimen/menu_icon_height"
android:padding="@dimen/menu_icon_padding"
android:clickable="true"
android:src="@drawable/ic_compare_selector"
android:background="?android:attr/selectableItemBackgroundBorderless"/>
在style中主题下添加:- @color/gray
方法二:
使用标签,在drawable下创建一个xml:
background_ripple_gray.xml
--------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/gray">
--------------------------------------------------------
使用
android:id="@+id/fb_cancel"
android:layout_width="@dimen/menu_icon_width"
android:layout_height="@dimen/menu_icon_height"
android:padding="@dimen/menu_icon_padding"
android:src="@drawable/ic_close_selector"
android:background="@drawable/background_ripple_gray" />
****************
ripple_red_with_pic_mask.xml 在边界内的涟漪效果
--------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
android:color="#FF0000" >
--------------------------------------------------------
在大多数情况下,在布局XML文件中使用如下的方法去指定视图的背景:
?android:attr/selectableItemBackground (有界波纹)
?android:attr/selectableItemBackgroundBorderless (无界波纹)
注意:selectableItemBackgroundBorderless是API级别21上的新属性。
要更改默认的触摸反馈颜色,使用主题的android:colorControlHighlight属性
例如:
android:layout_width="@dimen/menu_icon_width"
android:layout_height="@dimen/menu_icon_height"
android:padding="@dimen/menu_icon_padding"
android:clickable="true"
android:src="@drawable/ic_compare_selector"
android:background="?android:attr/selectableItemBackgroundBorderless"/>
在style中主题下添加:
方法二:
使用
background_ripple_gray.xml
--------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
android:color="@color/gray">
--------------------------------------------------------
使用
android:layout_width="@dimen/menu_icon_width"
android:layout_height="@dimen/menu_icon_height"
android:padding="@dimen/menu_icon_padding"
android:src="@drawable/ic_close_selector"
android:background="@drawable/background_ripple_gray" />
****************
ripple_red_with_pic_mask.xml 在边界内的涟漪效果
--------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
--------------------------------------------------------
更多相关文章
- Android(安卓)两种串口实现方法总结
- android onClick事件的不同写法
- Android(安卓)2017最新面试题 深圳华为 腾讯 中兴 腾讯详细解析
- Android开发——AsyncTask的使用以及源码解析
- Android(安卓)事件分发机制详解
- Vue和iOS、Android交互
- Android系统服务初始化源码分析
- Android学习笔记八之BroadCastReceiver
- android:targetSdkVersion 属性导致程序问题