Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background Ripple Effect on StandAlone Toolbar items is gone

Using the Standalone toolbar has an issue with the select able background of the items, following this article didn't work also:

http://blog.mohitkanwal.com/blog/2015/03/07/styling-material-toolbar-in-android/

Check the normal toolbar in the below screenshot, the ripple effect selector is gone when using the standalone toolbar.

here is my style:

 <style name="ToolbarTheme" parent="Widget.AppCompat.Toolbar">
        <item name="actionMenuTextColor">@color/green</item>
        <item name="drawerArrowStyle">@style/DrawerArrowToggle</item>
        <item name="colorControlNormal">@color/white</item>
        <item name="colorControlActivated">@color/white</item>
        <item name="android:textColorPrimary">@color/white</item>
        <item name="titleTextAppearance">@style/ActionBar.TitleText</item>
        <item name="android:actionOverflowButtonStyle">@style/MoreActionButton</item>
        <item name="actionButtonStyle">@style/Widget.AppCompat.ActionButton</item>
        <item name="selectableItemBackground">?android:selectableItemBackground</item>
        <item name="selectableItemBackgroundBorderless">?android:selectableItemBackground</item>
        <item name="colorControlHighlight">@color/accentColor</item>
    </style>

EDIT: After isolating the issue from my code I was able to reproduce the issue and it seems it is related to the new support design library. And here is the test code that has the issue:

TestToolbar.zip

enter image description here

like image 250
Mahdi Hijazi Avatar asked Jun 01 '15 15:06

Mahdi Hijazi


4 Answers

This was done using android 5.1 genymotion emulator

I didn't figure out your problem, but I just tried to create a toolbar the same as yours, but with removing some style that I don't have

here is my style

  <style name="ToolbarTheme"
      parent="Widget.AppCompat.Toolbar">
    <item name="actionMenuTextColor">#1bff3a</item>
    <item name="colorControlNormal">#FFF</item>
    <item name="colorControlActivated">#FFF</item>
    <item name="android:textColorPrimary">#FFF</item>
    <item name="actionButtonStyle">@style/Widget.AppCompat.ActionButton</item>
    <item name="selectableItemBackground">?android:selectableItemBackground</item>
    <item name="selectableItemBackgroundBorderless">?android:selectableItemBackground</item>
    <item name="colorControlHighlight">@color/accentColor</item>
  </style>

My Toolbar layout

 <android.support.v7.widget.Toolbar
      android:id="@+id/toolbar"
      android:layout_width="match_parent"
      android:layout_height="?attr/actionBarSize"
      android:background="?colorPrimary"
      app:theme="@style/ToolbarTheme"
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
      />

My Menu

<item
      android:id="@+id/action_settings"
      android:title="@string/action_settings"
      android:icon="@drawable/abc_ic_clear_mtrl_alpha"
      app:showAsAction="always"
      />

The activity code

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

Screenshot of the result

Screenshot of working toolbar


Edit

after downloading the sample you provided in the question, the problem has nothing to do with standalone toolbar or actionbar (both have the same problem) when using AppBarLayout, the problem seems that the Ripple effect will be drawn on AppBarLayout instead of the View of the selected menu item, I'll record a video explaining it.

the video: AppBarLayout with Toolbar Video

I'll try to find a solution for this.

like image 96
Mohammad Ersan Avatar answered Oct 31 '22 07:10

Mohammad Ersan


It looks like the ripple effect is still there but the ripple color has changed. I am not sure of what your problem is but this is what I see.

I suggest you remove

        <item name="colorControlHighlight">@color/accentColor</item>

from your code and run it again. If the ripples dont display (they should), change the accent color.

like image 28
Alok Narasiman Avatar answered Oct 31 '22 05:10

Alok Narasiman


The workaround regarding the selectableItemBackground also didn't work for me. The best strategy I came up till now is to set the background of the Toolbar to transparent:

<android.support.v7.widget.Toolbar
   ...
   android:background="@android:color/transparent"/>

This enables the ripple effect (cropped to the Actionbar heigth) in expanded/collapsed/intermediate state.

like image 6
Andreas Wenger Avatar answered Oct 31 '22 06:10

Andreas Wenger


This worked for me:

Define a custom theme in the styles.xml

<style name="MyAppbarTheme" parent="@style/ThemeOverlay.AppCompat.Light">
    <item name="colorControlHighlight">@color/colorAccent</item>
</style>

Then apply this theme on the AppBarLayout or Toolbar

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/MyAppbarTheme" >
like image 4
s-hunter Avatar answered Oct 31 '22 07:10

s-hunter