什么是Android的API level11前的替代getActionView()? [英] What is the alternative to getActionView() before API level11 in android?

查看:125
本文介绍了什么是Android的API level11前的替代getActionView()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

getActionView()的操作栏是在推出 API 11 ,如果我想向后兼容性什么是另类为 getActionView()

例如。

 公共布尔onCreateOptionsMenu(功能菜单){
   。getMenuInflater()膨胀(R.menu.action_bar_menu,菜单);

   最终的菜单项项= menu.findItem(R.id.menuitem);
   item.getActionView()的API级别11 //工程

   返回true;
}
 

解决方案

为了向下兼容,你可以使用 ActionBarCompat ActionBarScherlock 。在这两种情况下,你可以使用的方法 getActionView()。你必须确保进口,在第一种情况是从兼容性库( android.support.v4.view.MenuItemCompat )。如果 您使用 ActionBarSherlock 你有进口com.actionbarsherlock.view.MenuItem 。那么你应该使用是确定 item.getActionView()

<打击>自2013年8月,我祈求大家失望投票看一看。你必须确保该任择议定书的问题,进口日期,Android在第一种情况中介绍的是从兼容性库(ActionBarCompactandroid.support.v4.view.MenuItemCompat)。即使如果您使用ActionBarSherlock仍然是有效的选择,一个选择是走向ActionBarCompact。

所以,另一种选择就是使用它,当然,所有的importsyou都来自支持库,如: android.supportimport com.v4actionbarsherlock.view.MenuItemCompatMenuItem。然后,你应该确定使用item.getActionView()。

getActionView() for action bar was introduced in API 11, If I want backward compatibility what is the alternative for getActionView() ?

e.g.

public boolean onCreateOptionsMenu(Menu menu) {
   getMenuInflater().inflate(R.menu.action_bar_menu, menu);

   final MenuItem item = menu.findItem(R.id.menuitem);
   item.getActionView() //Works from API level 11

   return true;
}

解决方案

For backwards compatibility you can use either ActionBarCompat or ActionBarScherlock. In both cases you can use the method getActionView(). You have to be sure that the import, in the first case is from the compatibility library ( android.support.v4.view.MenuItemCompat). If you use ActionBarSherlock you have to import com.actionbarsherlock.view.MenuItem. Then you should be ok using item.getActionView().

Old

Since August 2013, and I pray people down-voting to take a look. You have to be sure that the OP's question date import, Android introduced in the first case is from the compatibility library ( ActionBarCompactandroid.support.v4.view.MenuItemCompat). Even though If you use ActionBarSherlock is still a valid choice, an option is moving towards ActionBarCompact.

So another option is to use it, and of course, all the importsyou have to came from the support library, e.g. android.supportimport com.v4actionbarsherlock.view.MenuItemCompatMenuItem. Then you should be ok using item.getActionView().

这篇关于什么是Android的API level11前的替代getActionView()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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