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

标签 android android-toolbar

我使用支持包中的新工具栏。

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

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

最佳答案

您可以使用以下方式更改样式中的按下状态效果

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

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

在 Android 5.0 上,您可以覆盖“style-v21”中的样式并设置波纹可绘制对象(在 drawable-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"/>

关于android - 如何更改支持工具栏菜单项的 onPress 行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27126805/

相关文章:

android - JPEG 压缩后如何预测图像大小(以兆字节为单位)

android - Retrofit 2.0 Beta 2 - 路径编码有问题吗?

Android工具栏颜色变化

android - 工具栏设置错误的图标

android - 单一 Activity 不会使工具栏的菜单膨胀

Android 支持 v7 工具栏 setTitleTextAppearance 不工作

java - 包通知兼容不存在

android - 如何检查列出的 WiFi AP 是否安全?

android - 如何在X86 linux中调用android动态库(.so)?

android - 不使用 Marshmallow 调用 Spinner onItemSelected