Android官方入门文档[11]支持不同平台版本

Android官方入门文档[11]支持不同平台版本


Supporting Different Platform Versions
支持不同平台版本

 

This lesson teaches you to
1.Specify Minimum and Target API Levels
2.Check System Version at Runtime
3.Use Platform Styles and Themes

You should also read
•Android API Levels
•Android Support Library

这节课教你
1.指定最小和目标API级别
2.检查系统版本在运行
3.使用平台的样式和主题

你也应该阅读
•Android的API级别
•Android的支持库

While the latest versions of Android often provide great APIs for your app, you should continue to support older versions of Android until more devices get updated. This lesson shows you how to take advantage of the latest APIs while continuing to support older versions as well.
而Android的最新版本经常为你的应用程序提供了巨大的API,你应该继续支持老版本的Android,直到更多的设备得到更新。本课向您展示如何利用最新的API的优势,同时继续支持旧版本也是如此。

The dashboard for Platform Versions is updated regularly to show the distribution of active devices running each version of Android, based on the number of devices that visit the Google Play Store. Generally, it’s a good practice to support about 90% of the active devices, while targeting your app to the latest version.
仪表板为平台版本会定期更新,以显示运行的每个版本的Android,基于该访问谷歌Play商店的设备数量激活设备的分布。一般情况下,这是一个很好的做法,支持约90%的激活设备,而针对您的应用程序至最新版本。

Tip: In order to provide the best features and functionality across several Android versions, you should use the Android Support Library in your app, which allows you to use several recent platform APIs on older versions.
提示:为了跨几款Android版本提供最佳的特性和功能,你应该使用Android的支持库在你的应用程序,它允许您使用最近几个平台API的旧版本。

 

Specify Minimum and Target API Levels
指定最小和目标API级别


--------------------------------------------------------------------------------

The AndroidManifest.xml file describes details about your app and identifies which versions of Android it supports. Specifically, the minSdkVersion and targetSdkVersion attributes for the <uses-sdk element identify the lowest API level with which your app is compatible and the highest API level against which you’ve designed and tested your app.
AndroidManifest.xml文件描述了你的应用程序识别其中的Android版本,它支持的细节。具体来说,minSdkVersion属性targetSdkVersion为<uses-sdk元素标识的最低API级别与您的应用程序是兼容的,最高的API水平,使你的设计和测试您的应用程序。

For example:
例如:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" ... >
    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" />
    ...
</manifest>

As new versions of Android are released, some style and behaviors may change. To allow your app to take advantage of these changes and ensure that your app fits the style of each user's device, you should set the targetSdkVersion value to match the latest Android version available.
由于Android的新版本发布,一些风格和行为可能会改变。为了让您的应用程序把这些变化的优势,并确保您的应用程序适合每个用户的设备的风格,你应该设置targetSdkVersion值以匹配最新的Android版本。

 

Check System Version at Runtime
在运行时检查系统版本

 

--------------------------------------------------------------------------------

Android provides a unique code for each platform version in the Build constants class. Use these codes within your app to build conditions that ensure the code that depends on higher API levels is executed only when those APIs are available on the system.
Android提供了每个平台版本生成的常量类的唯一代码。使用你的应用程序中的这些代码来构建确保执行依赖于较高的API级别,只有当这些API可在系统上的代码的条件。

Note: When parsing XML resources, Android ignores XML attributes that aren’t supported by the current device. So you can safely use XML attributes that are only supported by newer versions without worrying about older versions breaking when they encounter that code. For example, if you set the targetSdkVersion="11", your app includes the ActionBar by default on Android 3.0 and higher. To then add menu items to the action bar, you need to set android:showAsAction="ifRoom" in your menu resource XML. It's safe to do this in a cross-version XML file, because the older versions of Android simply ignore the showAsAction attribute (that is, you do not need a separate version in res/menu-v11/).
注:当解析XML资源,Android的忽略那些不支持当前设备XML属性。所以你可以放心地使用那些无需担心旧版本,他们遇到的代码时,打破仅受新版本XML属性。例如,如果你设置了targetSdkVersion=“11”,你的应用程序包括在Android3.0及更高的动作条在默认情况下。为了再添加菜单项的动作吧,你需要设置的android:在你的菜单资源XML showAsAction=“ifRoom”。它的安全做到这一点的跨版本的XML文件,因为旧版本的Android根本无视showAsAction属性(也就是,你并不需要一个单独的版本在res/menu-v11/)。

 

Use Platform Styles and Themes
使用平台样式和主题


--------------------------------------------------------------------------------

Android provides user experience themes that give apps the look and feel of the underlying operating system. These themes can be applied to your app within the manifest file. By using these built in styles and themes, your app will naturally follow the latest look and feel of Android with each new release.
Android提供的用户体验的主题,让应用程序底层操作系统的外观和感觉。这些主题可以应用到你的应用程序清单文件中。通过使用这些内置的风格和主题,你的应用程序自然会按照最新的Android外观和感觉与每个新版本。

To make your activity look like a dialog box:
为了让你的activity活动看起来像一个对话框:
<activity android:theme="@android:style/Theme.Dialog">

To make your activity have a transparent background:
为了让你的活动有一个透明的背景:
<activity android:theme="@android:style/Theme.Translucent">

To apply your own custom theme defined in /res/values/styles.xml:
适用于/res/values/styles.xml定义你自己的自定义主题:
<activity android:theme="@style/CustomTheme">

To apply a theme to your entire app (all activities), add the android:theme attribute to the <application> element:
要将主题应用到整个应用程序(所有活动),添加了android:theme属性到<应用程序>元素:
<application android:theme="@style/CustomTheme">

For more about creating and using themes, read the Styles and Themes guide.
欲了解更多有关创建和使用主题,阅读风格和主题指导。

  Next class: Managing the Activity Lifecycle
  下一们课程:管理活动的生命周期

本文翻译自:https://developer.android.com/training/basics/supporting-devices/platforms.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
[14本经典Android开发教程]-11-Android系统移植技术详解 -------------------------------------------------- (1)安装如下软件包 sudo apt-get install git-core sudo apt-get install gnupg sudo apt-get install sun-java5-jdk sudo apt-get install flex sudo apt-get install bison sudo apt-get install gperf sudo apt-get install libsdl-dev sudo apt-get install libesd0-dev sudo apt-get install build-essential sudo apt-get install zip sudo apt-get install curl sudo apt-get install libncurses5-dev sudo apt-get install zlib1g-dev .... -------------------------------------------------- 已上传9本: [14本经典Android开发教程]-1-Android开发从入门到精通 http://download.csdn.net/detail/cleopard/8355245 [14本经典Android开发教程]-2-Android开发手册—API函数详解 http://download.csdn.net/detail/cleopard/8374487 [14本经典Android开发教程]-3-Android SDK 中文开发文档 http://download.csdn.net/detail/cleopard/8380429 [14本经典Android开发教程]-4-Android应用程序开发36技 http://download.csdn.net/detail/cleopard/8380495 [14本经典Android开发教程]-5-linux Android基础知识总结 http://download.csdn.net/detail/cleopard/8380529 [14本经典Android开发教程]-6-Android驱动开发入门及手机案例开发分析教程 http://download.csdn.net/detail/cleopard/8388019 ....... 剩余3本稍后上传!@或直接从这里寻找@ http://download.csdn.net/user/cleopard/album @更多@ http://cleopard.download.csdn.net/ 福利 http://xuemeilaile.com 17份软件测试文档 http://download.csdn.net/album/detail/1425 13份WPF经典开发教程 http://download.csdn.net/album/detail/1115 C#资料合辑二[C#桌面编程入门篇] http://download.csdn.net/album/detail/957 C#资料合辑一[C#入门篇] http://download.csdn.net/album/detail/669 [Csharp高级编程(第6版)](共8压缩卷) http://download.csdn.net/album/detail/667 10个[精品资源]Java学习资料合辑[一] http://download.csdn.net/album/detail/663 10个C#Socket编程代码示例 http://download.csdn.net/album/detail/631 6份GDI+程序设计资源整合[全零分] http://download.csdn.net/album/detail/625 2014年移动游戏行业数据分析 http://download.csdn.net/detail/cleopard/8340331 一文读懂2014年全球互联网广告新生态 http://download.csdn.net/detail/cleopard/8340303

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值