Platforms HTML PDF
Platforms HTML PDF
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. The dashboard for Platform Versions (http://developer.android.com /about/dashboards/index.html) 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, its a good practice to support about 90% of the active devices, while targeting your app to the latest version.
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
Tip: In order to provide the best features and functionality across several Android versions, you should use the Android Support Library (/tools/support-library/index.html) in your app, which allows you to use several recent platform APIs on older versions.
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. p pr ri iv va at te e v vo oi id d setUpActionBar() { // Make sure we're running on Honeycomb or higher to use ActionBar APIs i if f (B Bu ui il ld d.VERSION.SDK_INT >= B Bu ui il ld d.VERSION_CODES.HONEYCOMB) { A Ac ct ti io on nB Ba ar r actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(t tr ru ue e); } } Note: When parsing XML resources, Android ignores XML attributes that arent 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 (/reference/android/app/ActionBar.html) 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/).
To make your activity look like a dialog box: < <a ac ct ti iv vi it ty y android:theme="@android:style/Theme.Dialog"> > To make your activity have a transparent background: < <a ac ct ti iv vi it ty y android:theme="@android:style/Theme.Translucent"> > To apply your own custom theme defined in /res/values/styles.xml: < <a ac ct ti iv vi it ty y android:theme="@style/CustomTheme"> > To apply a theme to your entire app (all activities), add the android:theme attribute to the <application> (/guide/topics/manifest/application-element.html) element: < <a ap pp pl li ic ca at ti io on n android:theme="@style/CustomTheme"> > For more about creating and using themes, read the Styles and Themes (/guide/topics/ui/themes.html) guide.