您的位置:首页 > 移动开发 > Android开发

Android 3.0 SDK中新增API详解

2011-02-10 15:50 337 查看
http://www.android123.com.cn/zhongwensdk/776.html: By: Android开发网原创

Android 3.0 SDK中新增了哪些API呢? 我们总结下平板系统honeycomb中的新特性, 首先需要澄清的是经过Android123发现设置模拟器的分辨率到普通WVGA这样的解析度时平板的特性自动消失和Android 2.3没有什么太大区别,按照这样来看未来Android 3.0除了兼容平板外还继续可以被手机所支持,据称3.0的代码针对A9双核CPU进行了进一步的改进。

一、Fragments 碎片容器

有关Android Fragments的内容,Android开发网在前几天已经用几篇文章详细讲解了下,大家可以从Fragment对比Activity - Android碎片介绍 一文开始了解。

二、Action Bar 活动栏

活动栏Action Bar可以替换传统的标题栏在Activity窗口中,包括程序图标和一些新接口在activity的选项菜单中,另外Action Bar允许你

Include select menu items directly in the Action Bar—as "action items"—for quick access to global user actions.
In your XML declaration for the menu item, include the attribute,
android:showAsAction
with a value of
"ifRoom"
. When there's enough room in the Action Bar, the menu item appears directly in the bar. Otherwise, the item is placed in the overflow menu, revealed by the icon on the right side of the Action Bar.

Add interactive widgets to the Action Bar—as "action views"—such as a search box.
In the XML for the menu item that should behave as an action view, include the
android:actionViewLayout
attribute with a layout resource for the action view or
android:actionViewClass
with the class name of the widget. Like action items, an action view appears only when there's room for it in the Action Bar. If there's not enough room, it is placed in the overflow menu and behaves like a regular menu item (for example, an item can provide a
SearchView
as an action view, but when in the overflow menu, selecting the item activates the search dialog).

Add an action to the application logo when tapped and replace it with a custom logo
The application logo is automatically assigned the
android.R.id.home
ID, which the system deliveres to your activity's
onOptionsItemSelected()
callback when tapped. Simply respond to this ID in your callback method to perform an action such as go to your application's "home" activity.

To replace the icon with a logo,

Add breadcrumbs for navigating backward through fragments

Add built in tabs and a drop-down list for navigation

Customize the Action Bar themes and custom backgrounds

有关ActionBar的文章,可以参考 Action Bar使用方法 - Android活动栏 系列文章

三、System clipboard系统剪切板

Android 3.0中的剪切板进行了增强,本次可以支持除了纯文本外更多的内容,如,URL和Intent,对于剪切板类ClipboardManager仍然通过getSystemService(CLIPBOARD_SERVICE)来实例化,新增的ClipData类用于管理具体的复制对象,可以在SDK的android.content.ClipData.Item中找到。 具体的使用Android123将在今后的文章中写道。

四、拖拽

开始拖拽内容在你的Activity中可以使用startDrag()方法在一个View中,这里View.DragShadowBuilder提供了拖拽时的阴影,对于拖拽的过程处理可以通过OnDragListener通过View的setOnDragListener()来设置,在拖拽的时候系统会自动调用onDrag()方法。

五、增强的appWidgets

Android 3.0的appWidget开始支持更丰富的控件,比如GridView, ListView, StackView, ViewFlipper和AdapterViewFlipper.而以前必须通过RemoteView显示一个文本或图片,本次全新的RemoteViewsService增强了桌面小插件的功能。

六、增强的状态提示栏

新增的Notification API可以丰富你的状态栏,新的Notification.Builder类可以帮助你轻松实现,支持大图标提示信息通过setLargeIcon方法, 通常显示一些社交类的软件,比如联系人照片,或相册缩略图,设置自定义状态栏,可以使用setTicker()方法。

七、内容加载器

新框架API提供了一个异步加载内容的泪,合并和UI组件和fragment来动态加载数据从工作者现成,使用CursorLoader子类来获取ContentResolver中的数据.

八、A2DP蓝牙和耳机控制API

Android honeycomb中没有忘记再次增强蓝牙,你可以通过初始化BluetoothProfile通过调用getProfileProxy()在处理 A2DP或耳机 HEADSET设置,BluetoothProfile.ServiceListener可以获取客户端连接或断开的回调。

九、动画框架

3.0中Android再次增强动画播放类,ObjectAnimator和LayoutTransition需要大家了解一些。

十、扩展UI框架

新增以下UI控件

AdapterViewAnimator
AdapterViewFlipper
CalendarView
ListPopupWindow
NumberPicker
PopupMenu
SearchView
StackView

十一、图形相关

1. 2D图形硬件加速Hardware accelerated 2D graphics , 在androidmanifest.xml的<application> 元素中添加android:hardwareAccelerated="true" 即可。他可以优化程序运行更平滑高效,在滚动和动画方面。

2.设置渲染模式,比如 LAYER_TYPE_HARDWARE 硬件加速和 LAYER_TYPE_SOFTWARE 使用 setLayerType() 方法.

3.渲染脚本对于3D图形方面大家可以看看Renderscript类。

上面是Android 3.0的主要改进,明天Android开发网将和大家一起说下强大的对于平板电脑比较重要的Action Bar活动栏。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: