如何更改支持工具栏菜单项的onPress行为?

问题描述:

我使用支持包中的新工具栏。如何更改支持工具栏菜单项的onPress行为?

在Android 5.0上,我获得了很好的触摸效果。 在较低版本中,我也得到了按下状态,但它非常微妙。

如何更改工具栏菜单项的按下状态?

+0

放' @ drawable/some_selector'里面你的风格/主题通常是'android \ support \ v7 \ appcompat \ res \ drawable \ abc_item_background_holo_(light/dark).xml' – Selvin 2014-11-25 13:57:50

你可以改变你的风格按下状态的影响

<item name="selectableItemBackground"> 
     @drawable/selectable_item_background_selector 
    </item> 

    <item name="android:selectableItemBackground"> 
     @drawable/selectable_item_background_selector 
    </item> 

在Android 5.0可以覆盖风格“风格-V21”,并设置一个波动绘制(在绘制-V21):

<item name="android:selectableItemBackgroundBorderless"> 
     @drawable/ripple_selector 
    </item> 

要更改按下状态风格只为工具栏,你可以设置自定义主题

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     app:theme="@style/ToolbarStyle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     android:minHeight="?attr/actionBarSize"/>