使用 actionLayout 触摸菜单项的反馈

Touch feedback on menu item with actionLayout

我正在使用带有 actionLayout 的菜单项,因为我需要为 ActionBar 上的项目添加一个 textView 和我的图标。一切都正确显示,但我不知道(也找不到任何地方)如何添加当用户点击 Lollipop 设备上的菜单项时显示的动画。

我想在工具栏的评论图标旁边显示评论数量。

这是我的资料:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/menu_like"
        android:icon="@drawable/list_discuss_like"
        android:title="Like"
        app:showAsAction="always"/>
    <item
        android:id="@+id/menu_comment"
        app:actionLayout="@layout/menu_item_comment"
        android:title="Comment"
        android:icon="@drawable/ic_comment_white_24dp"
        app:showAsAction="always"/>
</menu>

还有我的 menu_item_comment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:clickable="true"
              android:hapticFeedbackEnabled="true"
              android:orientation="horizontal">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:src="@drawable/ic_comment_white_24dp"/>

    <TextView
        android:id="@+id/ab_comment_count"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="(12)"
        android:textColor="@color/grayTextHint"/>

</LinearLayout>

动画和反馈适用于喜欢的项目,但不适用于评论项目。

感谢任何帮助。

将可点击元素的背景设置为主题的操作栏项目背景。

<LinearLayout
        ...
        android:clickable="true"
        android:background="?android:attr/actionBarItemBackground">
    ...
</LinearLayout>