Android官方入门文档[5]建立操作栏

简介: Android官方入门文档[5]建立操作栏 Setting Up the Action Bar建立操作栏This lesson teaches you to1.

Android官方入门文档[5]建立操作栏

 

Setting Up the Action Bar
建立操作栏

This lesson teaches you to
1.Support Android 3.0 and Above Only
2.Support Android 2.1 and Above

You should also read
•Setting Up the Support Library

这节课教你
1.仅支持Android3.0及以上
2.支持Android2.1及以上

你也应该阅读
•设置支持库

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.
在其最基本的形式中,操作栏显示的活性和在左侧的应用程序图标的标题。即使在这种简单的形式,操作栏是非常有用的所有活动,以告知用户他们在哪里,并保持你的应用程序一致。

Figure 1. An action bar with the app icon and activity title.
图1.应用程序图标和标题活动的操作栏。

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.
建立一个基本的操作栏需要你的应用程序使用的活动主题,使操作栏。如何申请这样一个主题取决于哪个版本的Android是最低的了您的应用程序的支持。所以,这个课程是分为两个部分,这取决于Android版本的最低支持。

 

Support Android 3.0 and Above Only
仅支持Android3.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主题(或它的子类),这是默认的主题时,无论是targetSdkVersion或的minSdkVersion属性被设置为“11“或更大。


So to add the action bar to your activities, simply set either attribute to 11 or higher. For example:
所以在操作栏添加到您的活动,只需设置任一属性为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 as its parent. For details, see Styling the Action Bar.
注:如果您已经创建了一个自定义主题,可以肯定它采用的Theme.Holo主题之一作为其父类。有关详细信息,请参见样式的操作栏。

Now the Theme.Holo theme is applied to your app and all activities show the action bar. That's it.
现在Theme.Holo主题应用到您的应用程序的所有活动显示操作栏。就是这样。

 

Support Android 2.1 and Above
支持Android2.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.
在旧比Android3.0(向下至Android2.1)版本上运行时,操作栏需要你在你的应用程序,包括Android的支持库。


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).

Once you have the Support Library integrated with your app project:
要开始,请阅读支持库安装文件,并成立了V7 appcompat库(一旦你下载的库包,按照说明添加库的资源)。

一旦你的支持库集成到您的应用程序的项目:

 

1.Update your activity so that it extends ActionBarActivity. For example:

1.更新你的活动,使其扩展ActionBarActivity。例如:

 

public class MainActivity extends ActionBarActivity { ... }


2.In your manifest file, update either the <application> element or individual <activity> elements to use one of the Theme.AppCompat themes. For example: 2.在你的manifest文件里,更新无论是<application>元素或个人<活动>元素使用的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主题之一作为其父类。有关详细信息,请参见样式的操作栏。

Now your activity includes the action bar when running on Android 2.1 (API level 7) or higher.
现在在Android2.1(API7级)或更高版本运行时,你的活动包括操作栏。

Remember to properly set your app's API level support in the manifest:
记住要正确设置你的应用程序的API级别支持manifest清单:

<manifest ... >
    <uses-sdk android:minSdkVersion="7"  android:targetSdkVersion="18" />
    ...
</manifest>

本文翻译自:https://developer.android.com/training/basics/actionbar/setting-up.html

目录
相关文章
|
16天前
|
Java 数据库 Android开发
【专栏】Kotlin在Android开发中的多线程优化,包括线程池、协程的使用,任务分解、避免阻塞操作以及资源管理
【4月更文挑战第27天】本文探讨了Kotlin在Android开发中的多线程优化,包括线程池、协程的使用,任务分解、避免阻塞操作以及资源管理。通过案例分析展示了网络请求、图像处理和数据库操作的优化实践。同时,文章指出并发编程的挑战,如性能评估、调试及兼容性问题,并强调了多线程优化对提升应用性能的重要性。开发者应持续学习和探索新的优化策略,以适应移动应用市场的竞争需求。
|
20天前
|
Java Android开发
Android系统 获取用户最后操作时间回调实现和原理分析
Android系统 获取用户最后操作时间回调实现和原理分析
22 0
|
21天前
|
Linux Android开发
测试程序之提供ioctl函数应用操作GPIO适用于Linux/Android
测试程序之提供ioctl函数应用操作GPIO适用于Linux/Android
14 0
|
4天前
|
Ubuntu Linux 开发工具
建立ubuntu下基于eclipse的android开发环境
建立ubuntu下基于eclipse的android开发环境
|
4天前
|
Android开发
Android游戏引擎AndEngine入门资料
Android游戏引擎AndEngine入门资料
|
4天前
|
Java Android开发
android AsyncTask入门
android AsyncTask入门
|
4天前
|
Java API 开发工具
java与Android开发入门指南
java与Android开发入门指南
11 0
|
21天前
|
XML Java API
Android 浅度解析:系统框架层修改,编译,推送相关操作
Android 浅度解析:系统框架层修改,编译,推送相关操作
27 0
|
1月前
|
XML 存储 Java
安卓应用开发入门:构建您的第一个移动应用
【4月更文挑战第13天】本文引导读者入门安卓应用开发,首先介绍设置开发环境,包括安装JDK和Android Studio。接着,通过Android Studio创建第一个项目,解析项目结构,重点讲解`AndroidManifest.xml`和`activity_main.xml`。然后,设计一个显示&quot;Hello World!&quot;的布局,并在`MainActivity.java`中编写相应逻辑。最后,运行并调试应用,鼓励读者继续学习安卓开发的更多知识,提升技能。
|
2月前
|
测试技术 API 调度
【Android 从入门到出门】第七章:开始使用WorkManager
【Android 从入门到出门】第七章:开始使用WorkManager
20 3
【Android 从入门到出门】第七章:开始使用WorkManager