如何将材料设计效果添加到android视图?

时间:2015-06-01 09:43:08

标签: android material-design

我正在使用AppCompat主题为Lollipop之前的版本提供材质主题。当我在Toolbar中将图像资源设置为导航图标或菜单按钮时,我会在点击它时获得涟漪效果(动作)。但是当我尝试在工具栏中提供相同的图标时,它们的行为就像普通视图一样,点击时没有动作。

如何创造涟漪? android是否能够在我提供的所有drawable上创建涟漪?当我在ImageView

中使用图像资源时,如何显示涟漪

3 个答案:

答案 0 :(得分:4)

您只需在XML布局中设置图像的背景即可创建纹波。
android:background="?android:attr/selectableItemBackground"

答案 1 :(得分:1)

Ripple基本上是RippleDrawable类的一个实例。您可以使用xml和<创建涟漪。涟漪>标签。最简单的波纹可绘制如下:

<?xml version="1.0" encoding="utf-8"?>
<ripple 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight" />

您可以在此处找到更多信息:http://blog.stylingandroid.com/ripples-part-1/

答案 2 :(得分:0)

你可以使用涟漪效应来实现这一目标。

从Android API 9 +的Material Design实现Ripple效果。

可以在Maven Central上找到lib,你可以用Gradle找到它,

document.getElementById('txtDFI').onkeydown = function() { return(integerAndFloatOnly()) }; 

用法

RippleView

使用像ImageView等内容在XML布局文件中声明RippleView。

  dependencies {
       compile 'com.github.traex.rippleeffect:library:1.3'
  }

如果您想知道Ripple效果何时结束,您可以在视图上设置一个监听器

  <com.andexert.library.RippleView
       android:id="@+id/more"
       android:layout_width="?android:actionBarSize"
       android:layout_height="?android:actionBarSize"
       android:layout_toLeftOf="@+id/more2"
       android:layout_margin="5dp"
       rv_centered="true">

    <ImageView
       android:layout_width="?android:actionBarSize"
       android:layout_height="?android:actionBarSize"
       android:src="@android:drawable/ic_menu_edit"
       android:layout_centerInParent="true"
       android:padding="10dp"
       android:background="@android:color/holo_blue_dark"/>

  </com.andexert.library.RippleView>

有关代码及更多信息,请参阅此链接:

https://github.com/traex/RippleEffect

更多设计:

https://github.com/wasabeef/awesome-android-ui