Android官方文档翻译 八 2.1Setting Up the Action Bar
Setting Up the Action Bar
建立Action Bar
This lesson teaches you to
这节课教给你
Support Android 3.0 and Above Only
仅仅支持Android 3.0及以上
Support Android 2.1 and Above
支持Android 2.1及其以上
You should also read
你还需要阅读
- Setting Up the Support Library
建立Support Library(支持类库)
In its most basic form, the action bar displays the title for the activity and the app icon on the left. Even in this simple form, the action bar is useful for all activities to inform users about where they are and to maintain a consistent identity for your app.
在它的最基本的形式中,action bar展示的是activity的标题,在标题左边是应用的图标。即使是在这种简单的形式中,action bar也是有用的,它可以在所有的activities中向用户通知他们当前在哪儿,并且可以始终保持一个对应你的应用程序的身份。

Figure 1. An action bar with the app icon and activity title.
图1 拥有一个应用程序图标和activity标题的action bar
Setting up a basic action bar requires that your app use an activity theme that enables the action bar. How to request such a theme depends on which version of Android is the lowest supported by your app. So this lesson is divided into two sections depending on which Android version is your lowest supported.
建立一个基本的action bar需要你的应用程序使用一个能够启用action bar的activity theme(activity主题)。如何请求这样一个主题取决于你的应用程序所支持的最低的Android版本是哪个。因此这堂课分成两节,根据你支持的最低的Android版本。
Support Android 3.0 and Above Only
仅仅支持Android 3.0及以上
Beginning with Android 3.0 (API level 11), the action bar is included in all activities that use the Theme.Holo theme (or one of its descendants), which is the default theme when either the targetSdkVersion or minSdkVersion attribute is set to “11” or greater.
从Android 3.0(API 11)开始,Theme.Holo主题(或者它的后代)已经把action bar包含进了所有的activities中,当你把目标SDK版本或者最低SDK版本属性设置成“11”或者更高时,这个主题便默认被选择了。
So to add the action bar to your activities, simply set either attribute to 11 or higher. For example:
因此要把action bar添加到你的activities中,只要设置任何一个属性到 11 或者更高就行。例如:
<manifest ... >
<uses-sdk android:minSdkVersion="11" ... />
...
</manifest>
Note: If you’ve created a custom theme, be sure it uses one of the Theme.Holo themes a 11d9 s its parent. For details, see Styling the Action Bar.
注意:如果你已经创建了一个自定义主题,请确保它使用Theme.Holo主题作为它的父母。更多详情,请看Styling the Action Bar。
Now the Theme.Holo theme is applied to your app and all activities show the action bar. That’s it.
现在你的应用程序已经应用了Theme.Holo主题了,所有的activities都会展现action bar了。这就是所有了。
Support Android 2.1 and Above
支持Android 2.1及其更高
Adding the action bar when running on versions older than Android 3.0 (down to Android 2.1) requires that you include the Android Support Library in your application.
当运行在一个Android 3.0以下(2.1以上)的版本上时,如果要添加一个action bar需要在你的应用程序中引用Android Support Library。
To get started, read the Support Library Setup document and set up the v7 appcompat library (once you’ve downloaded the library package, follow the instructions for Adding libraries with resources).
在开始以前,请阅读Support Library Setup文档,配置 v7 appcompat 工程(你曾经下载过这个工程包,跟着Adding Libraries with resources进行。)
Once you have the Support Library integrated with your app project:
一旦你把这个工程包整合到了你的项目中:
Update your activity so that it extends ActionBarActivity. For example:
更新你的activity,让它继承ActionBarActivity。例如:
public class MainActivity extends ActionBarActivity { ... }
In your manifest file, update either the element or individual
elements to use one of the Theme.AppCompat themes. For example:在你的manifest文件中,更新< application>元素或者只更新个别的< activity>元素,让它们使用Theme.AppCompat主题中的一个。例如:
<activity android:theme="@style/Theme.AppCompat.Light" ... >
Note: If you’ve created a custom theme, be sure it uses one of the Theme.AppCompat themes as its parent. For details, see Styling the Action Bar.
注意:如果你已经创建了一个自定义主题,请确保它使用Theme.AppCompat主题中的一个作为它的父母。想获取更多内容,请看Styling the Action Bar。
Now your activity includes the action bar when running on Android 2.1 (API level 7) or higher.
现在当你在Android 2.1(API 7)或者以上运行时,你的activity中就包含了action bar。
Remember to properly set your app’s API level support in the manifest:
请记住在manifest中正确地设置你的应用程序的API等级:
<manifest ... >
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="18" />
...
</manifest>
Next: Adding Action Buttons
下一课:增加动作按钮
这是我自己翻译的,如果您发现其中有重要错误,敬请指出。
Android官方文档翻译 八 2.1Setting Up the Action Bar的更多相关文章
- 【Android Developers Training】 5. 序言:添加Action Bar
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- Android设计和开发系列第二篇:Action Bar(Develop—API Guides)
Action Bar IN THIS DOCUMENT Adding the Action Bar Removing the action bar Using a logo instead of an ...
- android官方文档翻译(不断更新中。。。)
最近在自学android,抽空把官方文档的guide跟training差不多看了一遍,又对比了一些书籍,感觉还是官方文档讲得比较好,所以自己计划把官方文档翻译一下,方便自己的知识巩固以及复习查找,由于 ...
- Android官方文档翻译 九 2.2Adding Action Buttons
Adding Action Buttons 增加动作按钮 This lesson teaches you to 这节课教给你 Specify the Actions in XML 在XML中指定动作 ...
- Android官方文档翻译 十七 4.1Starting an Activity
Starting an Activity 开启一个Activity This lesson teaches you to 这节课教给你 Understand the Lifecycle Callbac ...
- Android官方文档翻译 十五 3.3Supporting Different Platform Versions
Supporting Different Platform Versions 支持不同的平台版本 This lesson teaches you to 这节课教给你 Specify Minimum a ...
- Android官方文档翻译 一 Getting Started
Getting Started 让我们开始吧! Welcome to Training for Android developers. 欢迎来到Android开发者训练营. Here you'll f ...
- Android官方文档翻译 十一 2.4Overlaying the Action Bar
Overlaying the Action Bar 叠加菜单栏 This lesson teaches you to 这节课教给你: Enable Overlay Mode 启用叠加模式 For An ...
- Android官方文档翻译 十 2.3Styling the Action Bar
Styling the Action Bar 设计菜单栏的样式 This lesson teaches you to 这节课教给你 Use an Android Theme 使用一个Android主题 ...
随机推荐
- [BUUCTF]PWN17——[HarekazeCTF2019]baby_rop
[BUUCTF]PWN17--[HarekazeCTF2019]baby_rop 附件 步骤: 例行检查,64位,开启了NX保护 试运行一下程序,看这个情况,当我们输入太长字符串的时候会报错 64位i ...
- 资源相关视图(Project)
<Project2016 企业项目管理实践>张会斌 董方好 编著 这里就扯到资源了,资源是啥意思?如果是教科书,怕又是有一个名词解释要背吧,吼吼--其实这个资源在这里的意思基本上猜就能猜到 ...
- 36、有效的数独 | 算法(leetode,附思维导图 + 全部解法)300题
零 标题:算法(leetode,附思维导图 + 全部解法)300题之(36)有效的数独 前言 1)码农三少 ,一个致力于 编写极简.但齐全题解(算法) 的博主. 2)文末附赠 价值上百美刀 资料. 一 ...
- UVA10079 Pizza Cutting 题解
Content 求用 \(n\) 条直线最多能将平面分成多少块区域. 多组输入,以一个负数结束. 数据范围:\(0\leqslant n\leqslant 2.1\times 10^8\). Solu ...
- java 编程基础 反射方式获取泛型的类型Fileld.getGenericType() 或Method.getGenericParameterTypes(); (ParameterizedType) ;getActualTypeArguments()
引言 自从JDK5以后,Java Class类增加了泛型功能,从而允许使用泛型来限制Class类,例如,String.class的类型实际上是 Class 如果 Class 对应的类暂时未知,则使 C ...
- 深入理解css中position属性及z-index属性 https://www.cnblogs.com/zhuzhenwei918/p/6112034.html
深入理解css中position属性及z-index属性 请看出处:https://www.cnblogs.com/zhuzhenwei918/p/6112034.html 在网页设计中,positi ...
- 四、Uniapp+vue+腾讯IM+腾讯音视频开发仿微信的IM聊天APP,支持各类消息收发,音视频通话,附vue实现源码(已开源)-会话好友列表的实现
会话好友列表的实现 1.项目引言 2.腾讯云后台配置TXIM 3.配置项目并实现IM登录 4.会话好友列表的实现 5.聊天输入框的实现 6.聊天界面容器的实现 7.聊天消息项的实现 8.聊天输入框扩展 ...
- 【LeetCode】1200. Minimum Absolute Difference 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcode ...
- 【LeetCode】553. Optimal Division 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- D. Persistent Bookcase(Codeforces Round #368 (Div. 2))
D. Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input stand ...