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
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
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.
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.
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.
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" >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With