menuitem 上的 actionlayout 什么都不做 [英] actionlayout on menuitem does nothing

查看:26
本文介绍了menuitem 上的 actionlayout 什么都不做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在菜单项上设置 actionLayout 并设置背景颜色和图像,但它不受尊重.在我的活动中,我有:

i am setting an actionLayout on a menu item and setting background color and image, but it's not respected. in my activity, i have:

getMenuInflater().inflate(R.menu.submit_action, menu);

我的 submit_action 是:

my submit_action is:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item android:id="@+id/action_submit"
        android:actionLayout="@layout/check"
        app:showAsAction="always"  />
</menu>

我的支票布局是

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="?android:attr/actionButtonStyle"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#e8e8e8"
    android:clickable="true"
    android:contentDescription="lol" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@null"
        android:scaleType="centerInside"
        android:src="@drawable/ic_action_tick" />

</RelativeLayout>

但即使有所有这些设置,这就是操作栏的显示方式,根本不显示我的菜单项(但它在那里,因为它响应点击,但没有出现):

but even with all of this setup, this is how the action bar appears, not showing my menuitem at all (but it's there, because it responds to the click, but doesn't appear):

推荐答案

尝试 app:actionLayout="@layout/check" 而不是 android:actionLayout="@layout/check".

如果您使用 ActionbarSherlockAppCompatandroid: 命名空间将不适用于 MenuItems.这是因为这些库使用了模仿 Android API 的自定义属性,因为它们在早期版本的框架中不存在.

If you're using ActionbarSherlock or AppCompat, the android: namespace will not work for MenuItems. This is because these libraries use custom attributes that mimic the Android APIs since they did not exist in earlier versions of the framework.

这篇关于menuitem 上的 actionlayout 什么都不做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆