美文网首页
Android实现点击波纹效果

Android实现点击波纹效果

作者: 难得糊涂与君勉 | 来源:发表于2020-03-09 16:43 被阅读0次

点击波纹效果

方法一

使用系统提供的RippleDraable,参考文章如下:
RippleDrawable

方法二

android:foreground="?selectableItemBackground"

需要注意的使用,使用此属性时候必须让当前View是可点击的。
如果在ListView或者GrdiView中使用如下:

 android:listSelector="?selectableItemBackground"

示例

<ImageView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:foreground="?attr/selectableItemBackground"
        />

这样ImageView图片之后,你点击图片时候会出现波纹的。

参考文章

点击变色

点击变色的原理,也是通过修改View的前景色来实现。

<style name="xxxxx">
        <item name="android:foreground">@drawable/click_drawable</item>
        <item name="android:clickable">true</item>
    </style>

click_drawable内容

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

    <item android:state_pressed="true">
        <shape>
            <solid android:color="" />  //你希望按压的下去的颜色
        </shape>
    </item>

    <item>
        <shape>
            <solid android:color="#00ffffff" />  //用户未按压时候的颜色,一般这个默认是看不见的
        </shape>
    </item>

</selector>

相关文章

网友评论

      本文标题:Android实现点击波纹效果

      本文链接:https://www.haomeiwen.com/subject/vibpdhtx.html