安卓兼容包

≯℡__Kan透↙ 提交于 2020-02-29 15:44:27

Eclipse创建安卓工程的时候,会多出来一个appcompat_v7包,莫名其妙。然后就去查查,这是个什么玩意儿。

恩,查了一圈回来,简单点理解就是:安卓碎片化很严重,有的可能还停留在10,但是现在的安卓版本都到23了,版本23肯定比10多了很多新的特性或效果啊,但是你10的系统上没有,而你又想要这么特性或效果,怎么办?那好,我就给你一个向下兼容的包,也就是appcompat_v7里面的这个架包啦,你的APP引入这个包,targetSDK即使是23的,放在10下面,新的特性也是可以使用的。当然咯,还有appcompat_v4啊appcompat_v13。

附上安卓关于支持库的官方文档。

Support Library

In this document

  1. Overview
  2. Backward Compatibility
  3. Support for General Layout Patterns
  4. Support for Different Form Factors
  5. General Utilities

See also

  1. Support Library Features
  2. Support Library Setup
  3. Support Library Revision History

The Android Support Library offers a number of features that are not built into the framework. These libraries offer backward-compatible versions of new features, provide useful UI elements that are not included in the framework, and provide a range of utilities that apps can draw on.

Overview


In many cases, a feature may be valuable to many app developers, but not appropriate to include in the Android framework itself. For example, an app might only need a feature for specialized use cases, such as to smooth the transition between different versions of the Android system.

To address these situations, the Android SDK includes several libraries collectively called the Android Support Library. App developers can include any of these libraries if they want to incorporate the library functionality into their apps.

Support libraries provide a range of different features:

Backward Compatibility


Figure 1. Because this app uses support library UI elements its interface incorporates material design principles, even though it is running on Android 4.4, which does not include native support for material design.

Support libraries allow apps running on older versions of the Android platform to support features made available on newer versions of the platform. For example, an app running on a version of Android lower than 5.0 (API level 21) that relies on framework classes cannot display material-design elements, as that version of the Android framework doesn't support material design. However, if the app incorporates the Support Library's appcompat library, the app has access to many of the features available in API level 21, including support for material design. As a result, your app can deliver a more consistent experience across a broader range of platform versions.

In some cases, the support library version of a class depends as much as possible on the functionality that the framework provides. In these cases, if an app calls one of the support class's methods, the support library's behavior depends on what version of Android the app is running on. If the framework provides the necessary functionality, the support library calls on the framework to perform the task. If the app is running on an earlier version of Android, and the framework doesn't expose the needed functionality, the support library may try to provide the functionality itself, or may act as a no-op. In either case, the app generally doesn't need to check what version of Android it's running on; instead, the app can rely on the support library to do those checks and choose appropriate behavior. Generally, classes whose names end in …Compat (like ActivityCompat) behave this way.

In other cases, the support library class provides a complete, standalone version of a framework class that does not rely on the availability of any framework APIs. These methods provide consistent behavior across all supported platforms.

In either case, the app does not need to check the system version at run time. The app can rely on the support library class to do the appropriate system checks, and modify its behavior as necessary.

Support for General Layout Patterns


Support libraries provide user interface elements not offered by the Android framework. For example, the Android Support Library offers additional layout classes, like DrawerLayout. These classes follow recommended Android design practices; for example, the Design Library follows the principles of material design in a way that works across many versions of Android.

By using these support library classes, you can avoid having to reinvent the wheel; if your app has a particular user interface requirement, you can draw on existing code, which provides a user interface that users will already be familiar with. These elements also help you build an app that looks and feels like a part of the Android ecosystem. For example, many apps need to display arbitrarily long lists of elements, and need to be able to quickly and efficiently reuse those elements as the list changes; this might be a list of emails, contacts, music albums, and so on. Those apps can use the support library RecyclerView widget to display the list. This saves the app developer from having to develop the list from scratch, and also ensures that the user will see a list that looks and behaves like lists in other apps.

Support for Different Form Factors


The Android SDK provides libraries for a number of different form factors, such as TV and wearables. An app can depend on the appropriate support library to provide functionality across a wide range of platform versions, and can provide content on external screens, speakers, and other destination devices.

General Utilities


The Android Support Library provides backward-compatible utility functions. Apps can use these utility functions to provide an appropriate user experience across a wide range of Android system versions. For example, support library permission methods behave appropriately depending on what platform version your app is running on. If the platform supports the runtime permissions model, these methods request the appropriate permission from the user; on platform versions that do not support the runtime permissions model, the methods check whether the appropriate permission was granted at install time.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!