Implementing Ripple Effect in Toolbar

送分小仙女□ 提交于 2019-12-12 08:18:19

问题


I am trying to add this Ripple effect on my toolbar https://github.com/traex/RippleEffect but currently I'm lost on how to do this.

base on how to add toolbar

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:background="@color/app_secondary_color" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.ActionBar" > 
</android.support.v7.widget.Toolbar>

then setting in Activity

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.inflateMenu(R.menu.menu_login);

Where should I put this

<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"
  ripple:rv_centered="true">


</com.andexert.library.RippleView>

回答1:


Use it like this:

<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"
 ripple:rv_centered="false">
   <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:background="@color/app_secondary_color" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.ActionBar" > 
   </android.support.v7.widget.Toolbar>

</com.andexert.library.RippleView>

Also do not forget to include this in your root layout.

    xmlns:ripple="http://schemas.android.com/apk/res-auto"

In your mainActivity(if toolbar is your action bar):

 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
    }


来源:https://stackoverflow.com/questions/27010265/implementing-ripple-effect-in-toolbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!