Bearbeiten von „Android Training/Supporting Different Platform Versions

Du bearbeitest die Quelle einer übersetzbaren Seite. Bitte stelle sicher, dass du mit der folgenden Dokumentation vertraut bist:

Warnung: Du bist nicht angemeldet. Deine IP-Adresse wird bei Bearbeitungen öffentlich sichtbar. Melde dich an oder erstelle ein Benutzerkonto, damit Bearbeitungen deinem Benutzernamen zugeordnet werden. Ein eigenes Benutzerkonto hat eine ganze Reihe von Vorteilen.

Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.

Aktuelle Version Dein Text
Zeile 1: Zeile 1:
<languages />
<languages />
<translate><!--T:1-->
<translate>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.
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.


<!--T:2-->
The dashboard for [http://developer.android.com/about/dashboards/index.html 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.
The dashboard for [http://developer.android.com/about/dashboards/index.html 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.


<!--T:3-->
'''Tip:''' In order to provide the best features and functionality across several Android versions, you should use the [http://developer.android.com/tools/support-library/index.html Android Support Library] in your app, which allows you to 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 [http://developer.android.com/tools/support-library/index.html Android Support Library] in your app, which allows you to use several recent platform APIs on older versions.


== Specify Minimum and Target API Levels == <!--T:4-->
== Specify Minimum and Target API Levels ==
The [http://developer.android.com/guide/topics/manifest/manifest-intro.html AndroidManifest.xml] file describes details about your app and identifies which versions of Android it supports. Specifically, the <code>minSdkVersion</code> and <code>targetSdkVersion</code> attributes for the <code>[http://developer.android.com/guide/topics/manifest/uses-sdk-element.html <uses-sdk]</code> 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.
The [http://developer.android.com/guide/topics/manifest/manifest-intro.html AndroidManifest.xml] file describes details about your app and identifies which versions of Android it supports. Specifically, the <code>minSdkVersion</code> and <code>targetSdkVersion</code> attributes for the <code>[http://developer.android.com/guide/topics/manifest/uses-sdk-element.html <uses-sdk]</code> 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.


<!--T:5-->
For example:</translate>
For example:</translate>
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
Zeile 20: Zeile 16:
</manifest>
</manifest>
</syntaxhighlight>
</syntaxhighlight>
<translate><!--T:6-->
<translate>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 <code>[http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#target targetSdkVersion]</code> value to match the latest Android version available.
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 <code>[http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#target targetSdkVersion]</code> value to match the latest Android version available.


== Check System Version at Runtime == <!--T:7-->
== Check System Version at Runtime ==
Android provides a unique code for each platform version in the <code>[http://developer.android.com/reference/android/os/Build.html Build]</code> 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.</translate>
Android provides a unique code for each platform version in the <code>[http://developer.android.com/reference/android/os/Build.html Build]</code> 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.</translate>
<syntaxhighlight lang="java">
<syntaxhighlight lang="java">
Zeile 34: Zeile 29:
}
}
</syntaxhighlight>
</syntaxhighlight>
<translate><!--T:8-->
<translate>'''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 <code>targetSdkVersion="11"</code>, your app includes the <code>[http://developer.android.com/reference/android/app/ActionBar.html ActionBar]</code> by default on Android 3.0 and higher. To then add menu items to the action bar, you need to set <code>android:showAsAction="ifRoom"</code> 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 <code>showAsAction</code> attribute (that is, you ''do not'' need a separate version in <code>res/menu-v11/</code>).
'''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 <code>targetSdkVersion="11"</code>, your app includes the <code>[http://developer.android.com/reference/android/app/ActionBar.html ActionBar]</code> by default on Android 3.0 and higher. To then add menu items to the action bar, you need to set <code>android:showAsAction="ifRoom"</code> 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 <code>showAsAction</code> attribute (that is, you ''do not'' need a separate version in <code>res/menu-v11/</code>).


== Use Platform Styles and Themes == <!--T:9-->
== 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 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.


<!--T:10-->
To make your activity look like a dialog box:</translate>
To make your activity look like a dialog box:</translate>
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<activity android:theme="@android:style/Theme.Dialog">
<activity android:theme="@android:style/Theme.Dialog">
</syntaxhighlight>
</syntaxhighlight>
<translate><!--T:11-->
<translate>To make your activity have a transparent background:</translate>
To make your activity have a transparent background:</translate>
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<activity android:theme="@android:style/Theme.Translucent">
<activity android:theme="@android:style/Theme.Translucent">
</syntaxhighlight>
</syntaxhighlight>
<translate><!--T:12-->
<translate>To apply your own custom theme defined in <code>/res/values/styles.xml</code>:</translate>
To apply your own custom theme defined in <code>/res/values/styles.xml</code>:</translate>
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<activity android:theme="@style/CustomTheme">
<activity android:theme="@style/CustomTheme">
</syntaxhighlight>
</syntaxhighlight>
<translate><!--T:13-->
<translate>To apply a theme to your entire app (all activities), add the <code>android:theme</code> attribute to the <code>[http://developer.android.com/guide/topics/manifest/application-element.html <application>]</code> element:</translate>
To apply a theme to your entire app (all activities), add the <code>android:theme</code> attribute to the <code>[http://developer.android.com/guide/topics/manifest/application-element.html <application>]</code> element:</translate>
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<application android:theme="@style/CustomTheme">
<application android:theme="@style/CustomTheme">
</syntaxhighlight>
</syntaxhighlight>
<translate><!--T:14-->
<translate>For more about creating and using themes, read the [http://developer.android.com/guide/topics/ui/themes.html Styles and Themes] guide.</translate>
For more about creating and using themes, read the [http://developer.android.com/guide/topics/ui/themes.html Styles and Themes] guide.</translate>


{{TNT|Android Training/Attribution}}
{{TNT|Android Training/Attribution}}
Bitte kopiere keine Webseiten, die nicht deine eigenen sind, benutze keine urheberrechtlich geschützten Werke ohne Erlaubnis des Urhebers!
Du gibst uns hiermit deine Zusage, dass du den Text selbst verfasst hast, dass der Text Allgemeingut (public domain) ist, oder dass der Urheber seine Zustimmung gegeben hat. Falls dieser Text bereits woanders veröffentlicht wurde, weise bitte auf der Diskussionsseite darauf hin. Bitte beachte, dass alle Android Wiki-Beiträge automatisch unter der „Creative Commons Attribution/Share-Alike Lizenz 3.0“ stehen. Falls du nicht möchtest, dass deine Arbeit hier von anderen verändert und verbreitet wird, dann klicke nicht auf „Seite speichern“.

Um das Wiki vor automatisiertem Bearbeitungsspam zu schützen, bitten wir dich, das folgende CAPTCHA zu lösen:

Abbrechen Bearbeitungshilfe (wird in einem neuen Fenster geöffnet)

Folgende Vorlagen werden auf dieser Seite verwendet: