Android 菜单和操作栏转换 [英] Android menu and action bar conversion

查看:27
本文介绍了Android 菜单和操作栏转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 中有一个新概念:

There is a new concept in Android:

http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html

但我不清楚.我有一个支持 1.6 到 4.0 的应用程序.我想遵循新概念,但我无法在菜单 xml 中设置 showAsAction 属性,因为:

But it isn't clear fro me. I have an application which is support from 1.6 to 4.0. And I want to follow the new concept, but I can't set showAsAction property in the menu xml because:

在包 'android' 中找不到属性 'showAsAction' 的资源标识符"

"No resource identifier found for attribute 'showAsAction' in package 'android'"

这是正常的,因为文档中有:

It's normal because there is in the doc:

注意:android:showAsAction 属性仅在 Android 3.0(API 级别 11)及更高版本上可用."

"Note: The android:showAsAction attribute is available only on Android 3.0 (API Level 11) and greater."

如何设置菜单,3.0以下是简单菜单,3.0以上是ActionBar?

How can I set the menu, that under 3.0 is a simple menu but over 3.0 as an ActionBar?

推荐答案

根据 博文:

总结

Android 不再需要专用的菜单按钮,有些设备没有,您应该不再使用它.

将 targetSdkVersion 设置为 14,然后在 Android 4.0 上测试您的应用.

Set targetSdkVersion to 14, then test your app on Android 4.0.

将 showAsAction="ifRoom" 添加到菜单项 您希望在操作栏中显示.

如果 ActionBar 不适用于您的应用,您可以使用 Theme.Holo.NoActionBar 或 Theme.DeviceDefault.NoActionBar 将其删除.

If the ActionBar doesn’t work for your app, you can remove it with Theme.Holo.NoActionBar or Theme.DeviceDefault.NoActionBar.

所以,你真正需要做的就是:

So, all you really have to do is this:

首先,像这样在 AndroidManifest.xml 文件中设置您的 SDK 最小值和目标版本:

First, set your SDK min and target version in the AndroidManifest.xml file like this:

<使用-sdkandroid:minSdkVersion="4"android:targetSdkVersion="14"/>

第二,将 showAsAction="ifRoom" 添加到 menu.xml 文件中的菜单项.

Second, add showAsAction="ifRoom" to the menu items in your menu.xml file.

现在在 Honeycomb 或 Ice Cream Sandwich 中运行您的应用,您应该会在操作栏中看到您的菜单.您的应用应该仍然适用于 Android 3.0 之前的版本.

Now run your app in Honeycomb or Ice Cream Sandwich and you should see your menu in the action bar. Your app should still work for the pre Android 3.0 releases.

这篇关于Android 菜单和操作栏转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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