Android的动作条的兼容性:MenuItem.setActionView(查看) [英] Android ActionBar compatibility: MenuItem.setActionView(View)

查看:1673
本文介绍了Android的动作条的兼容性:MenuItem.setActionView(查看)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是appcompat7 lib中的ActionBar向后兼容性。现在我有一个菜单项,我检索,然后需要设置 ImageView的MyView的作为它的图标。

I'm using the appcompat7 lib for ActionBar backwards compatibility. Now I have a MenuItem that I retrieve, and then want to set an ImageView myView as its icon.

的方式如何从API级别11做到这一点是:

The way how to do it from API level 11 is:

MenuItem menuItemRefresh = menu.findItem(R.id.refresh);
menuItemRefresh.setActionView(myView);

有关API等级低于11不起作用,第二行显示一个错误。是否有一个选项可以做到这一点在兼容模式下?

For API levels lower than 11 this doesn't work, the second line will show an error. Is there an option to do this in compatibility mode?

推荐答案

MenuItemCompat : <一href="http://developer.android.com/reference/android/support/v4/view/MenuItemCompat.html">http://developer.android.com/reference/android/support/v4/view/MenuItemCompat.html

有一个静态函数 setActionView(菜单项项目,查看视图)

所以,你的code应该是这样的:

So your code should look like:

MenuItem menuItemRefresh = menu.findItem(R.id.refresh);
menuItemRefresh = MenuItemCompat.setActionView(menuItemRefresh, myView);

这篇关于Android的动作条的兼容性:MenuItem.setActionView(查看)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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