Android控件点击效果

Android中Button控件是有点击效果的,但是像TextView、ImageView、各种Layout是没有点击效果的,给TextView设置点击事件后,加个点击效果用户触控反馈会好一点;

最简单的默认点击效果:

android:background="?android:attr/selectableItemBackground"

如果该空间已经有背景色了,可以设置前景色

android:foreground="?android:attr/selectableItemBackground"

这样一个Android原生的涟漪效果就出来了;

注意:

?android:attr/selectableItemBackgroundBorderless  <!--无边界涟漪效果-->
?android:attr/selectableItemBackground  <!--有边界涟漪效果-->

前景色:foreground属性只能给控件和帧布局设置,其它的布局设置无效果,具体看Android源码;

也可自定义,按照你的需求来:

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/abc_list_selector_disabled_holo_light" />
    <item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/abc_list_selector_disabled_holo_light" />
    <item android:state_focused="true"                                android:state_pressed="true" android:drawable="@drawable/abc_list_selector_background_transition_holo_light" />
    <item android:state_focused="false"                               android:state_pressed="true" android:drawable="@drawable/abc_list_selector_background_transition_holo_light" />
    <item android:state_focused="true"                                                             android:drawable="@drawable/abc_list_focused_holo" />
    <item                                                                                          android:drawable="@android:color/transparent" />
</selector>

 

posted on 2019-04-18 17:13  香蕉你个博纳纳  阅读(2323)  评论(0编辑  收藏  举报