Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

android - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...