Android official Getting Started document [11] support for different platform versions

Source: Internet
Author: User
Tags xml attribute

Android official Getting Started document [11] support for different platform versions
Supporting Different Platform Versions
Support for different platform versions

This lesson teaches
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

This lesson teaches you
1. Specify the minimum and target API levels
2. Check that the system version is running
3. Using the platform's styles and themes

You should also read
? API level for Android
? Support Library for Android

While the latest versions of Android often provide great APIs for your apps, you should continue to support older versions of Android until more devices get updated. This lesson shows the advantage of the latest APIs and continuing to support older versions as well.
While the latest version of Android often provides a huge API for your application, you should continue to support older versions of Android until more devices are updated. This lesson shows you how to take advantage of the latest APIs while continuing to support older versions as well.

The dashboard for Platform Versions are updated regularly to show the distribution of active devices running each version O F 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 .
The dashboard for the platform version will be updated periodically to show each version of Android running, activating the distribution of devices based on the number of devices that access the Google Play store. In general, this is a good practice to support about 90% of the activation device, while targeting your application to the latest version.

Tip:in order to provide the best features and functionality across several Android versions, your should use the Android S Upport Library in your app, which allows-use several recent-platform APIs on older versions.
Tip: In order to provide the best features and functionality across several Android versions, you should use the Android support library in your application, which allows you to use the previous versions of the last few platform APIs.

Specify Minimum and Target API levels
Specifying the minimum and target API levels


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

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 are compatible and the highest API level against which you ' ve designed and tested your app.
The Androidmanifest.xml file describes the details of the Android version that your application recognizes, which it supports. Specifically, the Minsdkversion property targetsdkversion is the lowest API level identified for <USES-SDK elements that is compatible with your application, with the highest API level that enables you to design and test your application.

For example:
For example:

<manifest xmlns:android= " http://schemas.android.com/apk/res/android "... >
<USES-SDK android:minsdkversion= "4" android:targetsdkversion= "/>"
...
</manifest>

As new versions of Android are released, some style and behaviors. To allow your app to take advantage of these changes and ensure that your app fits the style of each user's device, you sh Ould set the Targetsdkversion value to match the latest Android version available.
Some styles and behaviors may change as new versions of Android are released. In order for your application to take advantage of these changes and make sure that your application fits the style of each user's device, you should set the Targetsdkversion value to match the latest Android version.

Check System Version at Runtime
Check the system version at run time

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

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 this depends on higher API levels are executed onl Y when those APIs is available on the system.
Android provides unique code for the constant classes generated by each platform version. Use these code in your application to build conditions that ensure that execution relies on higher API levels, only when these APIs are available on the system code.

Note:when parsing XML Resources, Android ignores XML attributes that aren ' t supported by the current device. So-can safely use XML attributes that is only supported by newer versions without worrying about older versions break ing when they encounter that code. For example, if you set the targetsdkversion= "one", the 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 att Ribute (That's, you don't need a separate version in res/menu-v11/).
Note: When parsing XML resources, Android ignores those XML attributes that do not support the current device. So you can confidently use those that don't have to worry about older versions when they encounter code that breaks only by the new version of the XML attribute. For example, if you set the targetsdkversion= "11", your application is included in the Android3.0 and higher action bars by default. To add the action of the menu item again, you need to set the android: XML showasaction= "Ifroom" in your menu resource. It's safe to do this across versions of the XML file because the old version of Android simply ignores the Showasaction attribute (that is, you don't need a separate version in res/menu-v11/).

Use Platform Styles and Themes
Working with 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 would naturally follow the latest look and feel of Android with each NE W release.
Android provides a user experience theme that gives the application the look and feel of the underlying operating system. These topics can be applied to your application manifest file. By using these built-in styles and themes, your app will naturally follow the latest Android look and feel with each new version.

To make your activity look like a dialog box:
To make your activity look like a dialog box:
<activity android:theme= "@android: Style/theme.dialog" >

To make your activity has a transparent background:
In order for your activity to have a transparent background:
<activity android:theme= "@android: Style/theme.translucent" >

To apply your own custom theme defined in/res/values/styles.xml:
For/res/values/styles.xml define your own custom theme:
<activity android:theme= "@style/customtheme" >

To apply a theme to your entire app (all activities), add the Android:theme attribute to the <application> element:
To apply the theme to the entire application (all activities), add the Android:theme attribute to the < application > element:
<application android:theme= "@style/customtheme" >

For more on creating and using themes, read the Styles and Themes guide.
Learn more about creating and using themes, reading styles and topic guidance.

Next class:managing the Activity Lifecycle
Next lesson: Managing the life cycle of an activity

This article is translated from: https://developer.android.com/training/basics/supporting-devices/platforms.html

Android official Getting Started document [11] support for different platform versions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.