android api 资源限定符 - 如何设置范围?

android api resource qualifier - how to do ranges?

我需要根据设备 android 中的 API 级别设置不同的菜单选项。具体来说,对于 API 10 - 15,我需要一个特定的菜单,对于 API 16 及以后,我需要另一个菜单。我的应用程序 minSdkVersion 是 api 10。

现在菜单资源结构如下所示:

res/menu/menu.xml       (Default)
res/menu-v10/menu.xml    
res/menu-v11/menu.xml
res/menu-v12/menu.xml
res/menu-v13/menu.xml
res/menu-v14/menu.xml
res/menu-v15/menu.xml

我真的必须为每个级别添加一个菜单项吗?或者我可以在一个范围内添加它吗?

我希望我能做到这一点:

res/menu/menu.xml       (Default)
res/menu-v10-v15/menu.xml 

有没有办法以这种方式指定范围?我在 docs

中没有看到

Is there a way to specify ranges in this way ?

不是那样的。

do i really have to add a menu item for each level

你不知道。

Specifically, for API 10 - 15 i need a specific menu and for API 16 and beyond i need another menu

然后有两个目录:

  • res/menu/menu.xml API 10-15 级
  • res/menu-v16/menu.xml API 级别 16+

这假设您的 minSdkVersion 是 10。