安卓:菜单项自定义视图 [英] Android: Custom view for a menu item

查看:85
本文介绍了安卓:菜单项自定义视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够指定一个菜单项

I want to be able to specify a custom view for a MenuItem.

我要显示在购物车中的菜单项,在操作栏中显示的许多项目是如何在车目前的指标。

I want to display an indicator on a shopping cart menu item in the action bar displaying how many items are in the cart currently.

是我能做到这一点的唯一方法是通过添加自定义视图,而不是利用菜单项的生命周期等?

Is the only way that I can do this is through adding a custom view instead of utilising the MenuItem lifecycle etc.?

推荐答案

要在菜单项叫<一href="http://developer.android.com/reference/android/view/MenuItem.html#setActionView%28android.view.View%29">setActionView(View视图)。

您可以提供要么是已经膨胀的视图或布局资源ID。

You can supply either an already inflated view or a layout resource ID.

这篇关于安卓:菜单项自定义视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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