Android Learning Route (19) support for different devices--support for different (Android) platform versions

Source: Internet
Author: User
Tags xml attribute

When the latest Android version provides great APIs for your app, you will continue to support the old system version before more devices are updated. This course how to use the new version of the Advanced API in the case of continued support for the lower version of the system.

The Platform Versions Dashboard showcases the distribution of Android system versions running on the latest active devices, based on the number of devices accessing the Google Play store. In general, it is a good practice to support 90% of active devices while using the latest version as Target.

tip: to provide the best features and functionality on different Android versions, you should use the Android support Library in your app, which allows you to use some of the most recent APIs on older versions of your system.

Specify the minimum and target API levels

The Androidmanifest.xml file describes the details of your app and the version of the system it supports. Specifically, the <USE-SDK element's minSdkVersion and targetSdkVersion attributes specify the minimum API level to apply and the highest level of API that you have designed and tested for your app.

For example:

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

Due to the release of the new Android system, some styles and behaviors can be changed. To allow your app to take advantage of these changes and make sure your app uses each user's device, you'll need to targetSdkVersion set the value to the lowest available Android version.

Check the system version at run time

Android provides a unique identifier for each platform version in the Build constant class. Use this identifier in your app to create conditions to ensure that high API-level code is executed only when the system version is supported.

Private voidSetupactionbar() {    //Make sure we ' re running in honeycomb or higher to use ActionBar APIs    if (Build.VERSION.Sdk_int>= Build.Version_codes.Honeycomb) {        ActionBarActionBar=Getactionbar();ActionBar.setdisplayhomeasupenabled(true);    }}

tip: when parsing an XML resource, the Android system ignores the case where the XML attribute is not supported by the current device. So you can safely use only the latest version of the XML attribute without worrying about crashing on the old version. For example, if you set up targetSdkVersion="11" , your app is included by default in Android 3.0 or later ActionBar . Then to add a menu item for the Action bar, you need to set it in the resource file under your menu android:showAsAction="ifRoom" . In a cross-version of the XML file This is also absolutely no problem, because the old version of Android directly ignores this attribute (so that you do not need to separate the creation of a res/menu-v11/ directory).

Using the platform's styles and themes

Android provides users with a user experience theme that gives them the interface and feel of the underlying operating system. These topics can be applied in your app's manifest file. By setting up these built-in styles and themes, your app will have the interface and feel of each release version.

Make your activity look like a dialog box:

<activityandroid:theme="@android: Style/theme.dialog">

Make your activity background transparent:

<activity    android:theme  =   "@android: style/ Theme.translucent " >  

apply your / Custom theme:

<activityandroid:theme="@style/customtheme">

To have the theme apply to the entire app (all activity), <application> add the Android:theme attribute to the element:

<applicationandroid:theme="@style/customtheme">

For more information on creating and using themes, see the Styles and Themes wizard.

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.