Android实现水波纹点击效果

 更新时间:2017年03月02日 11:55:49   作者:Android_yyx  
这篇文章主要为大家详细介绍了Android实现水波纹点击效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

Android实现水波纹点击效果只在Android5.0以上版本有效,水波纹点击效果代码供大家参考,具体内容如下


圆角背景的水波纹效果(如上图)

1. 定义一个普通圆角背景的xml;

rounded_corners.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle">
 <solid android:color="#FFFFFF" />
 <corners android:radius="4dp" />
</shape>

2. 这里是重点,<ripple>是API21才有的新Tag,正是实现水波纹效果的;
其中<ripple Android:color="#FF21272B" .... />这个是指定水波纹的颜色,而<item />里面的东西,我们都很熟悉,就是普通的定义一个带圆角的背景。

ripple_bg.xml:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
 android:color="#FF21272B">
 <item>
  <shape android:shape="rectangle">
   <solid android:color="#FFFFFF" />
   <corners android:radius="4dp" />
  </shape>
 </item>
 <item android:drawable="@drawable/rounded_corners" />
</ripple>

3. 这是Activity的布局xml;

<Button android:background="@drawable/ripple_bg"... />直接使用ripple_bg作为背景。

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:gravity="center"
 android:orientation="vertical"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context=".MainActivity">

 <TextView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="@string/hello_world" />

 <Button
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@drawable/ripple_bg"
  android:text="@string/hello_world" />
</LinearLayout>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • android 中win10 使用uwp控件实现进度条Marquez效果

    android 中win10 使用uwp控件实现进度条Marquez效果

    这篇文章主要介绍了android 中win10 使用uwp控件实现进度条Marquez效果,需要的朋友可以参考下
    2017-06-06
  • Android 模拟器(JAVA)与C++ socket 通讯 分享

    Android 模拟器(JAVA)与C++ socket 通讯 分享

    Android 模拟器(JAVA)与C++ socket 通讯 分享,需要的朋友可以参考一下
    2013-05-05
  • Kotlin Dispatchers协程调度器源码深入分析

    Kotlin Dispatchers协程调度器源码深入分析

    Kotlin协程不是什么空中阁楼,Kotlin源代码会被编译成class字节码文件,最终会运行到虚拟机中。所以从本质上讲,Kotlin和Java是类似的,都是可以编译产生class的语言,但最终还是会受到虚拟机的限制,它们的代码最终会在虚拟机上的某个线程上被执行
    2022-11-11
  • Android WebView拦截iframe标签内部跳转教程

    Android WebView拦截iframe标签内部跳转教程

    这篇文章主要介绍了Android WebView拦截iframe标签内部跳转教程,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-03-03
  • Android实战项目之实现一个简单计算器

    Android实战项目之实现一个简单计算器

    随着移动互联网的普及,手机应用程序已经成为人们生活中不可或缺的一部分,计算器是一类被广泛使用的应用程序之一,这篇文章主要给大家介绍了关于Android实战项目之实现一个简单计算器的相关资料,需要的朋友可以参考下
    2023-10-10
  • Android开发apk反编译和二次打包教程

    Android开发apk反编译和二次打包教程

    反编译不是让各位开发者去对一个应用破解搞重装什么的,主要目的是为了促进开发者学习,借鉴好的代码,提升自我开发水平。下面我们就来研究下如何进行APK反编译以及二次打包
    2016-04-04
  • Android ServiceManager的启动和工作原理

    Android ServiceManager的启动和工作原理

    这篇文章主要介绍了Android ServiceManager的启动和工作原理,帮助大家更好的理解和学习使用Android开发,感兴趣的朋友可以了解下
    2021-03-03
  • 详解Android Handler机制和Looper Handler Message关系

    详解Android Handler机制和Looper Handler Message关系

    Handler是Android线程之间的消息机制,主要的作用是将一个任务切换到指定的线程中去执行,准确的说是切换到构成Handler的looper所在的线程中去出处理。本文将详细介绍Android Handler机制和Looper Handler Message关系。
    2021-06-06
  • Android GestureDetector实现手势滑动效果

    Android GestureDetector实现手势滑动效果

    这篇文章主要为大家详细介绍了Android GestureDetector实现手势滑动效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-05-05
  • Android 夜间模式的实现代码示例

    Android 夜间模式的实现代码示例

    本篇文章主要介绍了Android 夜间模式的实现代码示例,实现能够根据不同的设定,呈现不同风格的界面给用户,有兴趣的可以了解一下。
    2017-03-03

最新评论