支援資料庫
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
注意:Android 9.0 (API 級別 28) 版本包含
新版支援資料庫
Jetpack 中的 AndroidX。
AndroidX 程式庫
包含現有的支援資料庫,並包含最新的 Jetpack 元件。
您可以繼續使用支援資料庫。
歷來構件 (包含 27 以下版本,並以 android.support.*
封裝)
繼續透過 Google Maven 存取不過,所有新的程式庫開發程序
AndroidX 程式庫建立。
建議您在所有新專案中使用 AndroidX 程式庫。建議您考慮
將現有專案遷移至 AndroidX。
開發支援多個 API 版本的應用程式時,您可能需要
在舊版 Android 或
優雅地改回使用同等功能與其建構程式碼
可以處理舊版平台,可以利用這些程式庫
為您提供相容性層另外,支援資料庫
提供其他便利類別和功能,
標準架構 API,可簡化多個應用程式的開發與支援作業
裝置。
Android 支援資料庫原本是應用程式單一二進位程式庫
開發成一系列程式庫
用於開發應用程式許多解決方案
如果應用程式並非必要,我們現在強烈建議你使用程式庫
。
本文件將概略說明支援資料庫可協助您
瞭解元件的元件,以及如何在應用程式中有效使用
注意:從支援資料庫 26.0.0 版開始
(2017 年 7 月),大多數支援程式庫支援的最低 API 級別
針對大多數的程式庫套件,已提高為 Android 4.0 (API 級別 14)。適用對象
詳情請參閱版本支援與套件
名稱。
支援資料庫的用途
支援資料庫有幾種不同的用途。向後
適用於舊版平台的相容性類別只是
具體做法是指示 Kubernetes 建立並維護
一或多個代表這些 Pod 的物件以下更完整列出支援資料庫的使用方式
:
-
適用於較新 API 的回溯相容性 - 大幅
支援資料庫可為較新的架構提供回溯相容性
各種類別和方法例如:
Fragment
支援類別支援在執行版本的裝置上使用片段
Android 3.0 (API 級別 11) 以下版本。
-
便利與輔助類別:支援程式庫提供
的輔助類別數量,特別是用於使用者介面開發。適用對象
例如,
RecyclerView
類別可提供使用者
介面小工具,用於顯示及管理非常長的清單,
API 級別 7 以上的 Android 版本。
-
偵錯和公用程式:有許多功能
除了程式碼之外,還提供其他實用功能,包括
support-annotations
針對方法輸入改善程式碼 Lint 檢查功能,並支援 Multidex 支援,
可讓您透過超過 65,536 種方法設定及發布應用程式
使用 Support 與 Framework API
支援資料庫提供與以下項目相似的類別和方法:
Android 架構發現這些資訊後,你可能會思考是否應該
使用 API 的架構版本或同等的支援資料庫。這裡
使用支援資料庫類別的時機
架構 API:
支援資料庫類別,提供平台的相容實作
API 類別可能無法提供完整的功能
因為主機裝置具有限制,所以最新的版本提供
平台版本。在這些情況下,支援資料庫類別的設計宗旨就是
優雅降級,且可能無法提供
當前的平台 API因此,建議您查看參考檔案
程式庫類別和方法的說明文件,以及
執行測試,而且是在搭載最新支援平台版本的裝置上
注意:支援資料庫不提供同等項目
各個架構 API 的類別和方法在某些情況下,您可能需要
使用明確的 SDK 版本檢查來納入架構方法呼叫,並提供
用於處理裝置上不支援方法的替代程式碼。如要
若要瞭解如何在程式碼中使用版本檢查,請參閱支援不同的
平台版本。
版本支援和套件名稱
部分支援資料庫套件含有用來指出
最低支援 API 級別
透過 v# 標記法
support-v4 套件的說明。自支援資料庫 26.0.0 版 (已推出
2017 年 7 月),支援的最低 API 級別已改為 Android 4.0 (API)
級別 14)。所以說
任何近期版本的支援資料庫,不應假設
v# 套件標記法表示最低 API 支援等級。
本次異動也意味著,包含 v4 的程式庫套件
和第 7 版基本上等於其支援的最低 API 級別。
舉例來說,support-v4 和 support-v7 套件都支援最低規格
API 級別為 14,適用於 26.0.0 以上版本的支援資料庫。
支援資料庫發布版本
24.2.0 或 25.0.1 版
與該程式庫中任何程式庫支援的最低 API 級別不同
版本編號。版本編號會指出平台的版本
也是以 API 為基礎建構而成,因此最近使用的 API
包含這個版本的程式庫
具體來說,是版本編號的第一部分,例如
中的 24 版,通常會與
推出時可以使用的平台 API發布版本的
支援資料庫指出,它結合了該 API 的部分功能
不過,請勿假定這種引擎可與 all 相容
新功能。
程式庫依附元件
Android 支援資料庫套件中大部分的程式庫都具備某些依附元件
一或多個程式庫例如,幾乎所有支援資料庫都有
support-compat
套件的依附元件。一般來說
不必擔心如何支援程式庫依附元件
這項工具會自動加入
相依程式庫
如果想查看哪些程式庫和程式庫依附元件
在應用程式開發的建構根目錄中執行下列指令
,取得該專案的依附元件報表,包括
Android 支援資料庫和其他程式庫:
gradle -q dependencies your-app-project:dependencies
如要進一步瞭解如何為開發應用程式新增支援資料庫
專案。詳情請參閱「支援
程式庫設定。如要進一步瞭解如何使用 Gradle,請參閱
設定
您的版本。
請注意,所有 Android 支援資料庫也依附於部分基礎等級
最新的版本為 Android 4.0 (API 級別 14) 或
更高。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2024-08-23 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2024-08-23 (世界標準時間)。"],[],[],null,["# Support Library\n\n**Note:** With the release of Android 9.0 (API level 28) there is\na new version of the support library called\n[AndroidX](/jetpack/androidx) which is part of [Jetpack](/jetpack).\nThe AndroidX library\ncontains the existing support library and also includes the latest Jetpack components.\n\n\u003cbr /\u003e\n\n\nYou can continue to use the support library.\nHistorical artifacts (those versioned 27 and earlier, and packaged as `android.support.*`) will\nremain available on Google Maven. However, all new library development\nwill occur in the [AndroidX](/jetpack/androidx) library.\n\n\u003cbr /\u003e\n\n\nWe recommend using the AndroidX libraries in all new projects. You should also consider\n[migrating](/jetpack/androidx/migrate) existing projects to AndroidX as well.\n\n\nWhen developing apps that support multiple API versions, you may want a\nstandard way to provide newer features on earlier versions of Android or\ngracefully fall back to equivalent functionality. Rather than building code\nto handle earlier versions of the platform, you can leverage these libraries\nto provide that compatibility layer. In addition, the Support Libraries\nprovide additional convenience classes and features not available in the\nstandard Framework API for easier development and support across more\ndevices.\n\n\nOriginally a single binary library for apps, the Android Support Library has\nevolved into a suite of libraries for app development. Many of these\nlibraries are now a strongly recommended, if not essential, part of app\ndevelopment.\n\n\nThis document provides an overview of the support library to help you\nunderstand its components and how to use it effectively in your app.\n\n\n**Caution:** Starting with Support Library release 26.0.0\n(July 2017), the minimum supported API level across most support libraries\nhas increased to Android 4.0 (API level 14) for most library packages. For\nmore information, see [Version Support and Package\nNames](#api-versions) on this page.\n\nUses for the Support Libraries\n------------------------------\n\n\nThere are a few distinct uses for the support libraries. Backward\ncompatibility classes for earlier versions of the platform is just one of\nthem. Here is a more complete list of ways you can use the support libraries\nin your app:\n\n- **Backward Compatibility for newer APIs** - A large amount of the support libraries provide backward compatibility for newer framework classes and methods. For example, the [Fragment](/reference/androidx/fragment/app/Fragment) support class provides support for fragments on devices running versions earlier than Android 3.0 (API level 11).\n- **Convenience and Helper Classes** - The support libraries provides a number of helper classes, particularly for user interface development. For example the [RecyclerView](/reference/androidx/recyclerview/widget/RecyclerView) class provides a user interface widget for displaying and managing very long lists, useable on versions of Android from API level 7 and up.\n- **Debugging and Utilities** - There are a number of features that provide utility beyond code you incorporate into your app, including the [`support-annotations`](/studio/write/annotations) library for improved code lint checks on method inputs and [Multidex support](/studio/build/multidex) for configuring and distributing apps with over 65,536 methods.\n\nUsing Support versus Framework APIs\n-----------------------------------\n\n\nSupport Libraries provide classes and methods that closely resemble APIs in\nthe Android Framework. Upon discovering this, you may wonder if you should\nuse the framework version of the API or the support library equivalent. Here\nare the guidelines for when you should use support library classes in place\nof Framework APIs:\n\n- **Compatibility for a Specific Feature** - If you want to support a recent platform feature on devices that are running earlier versions of the platform, use the equivalent classes and methods from the support library.\n- **Compatibility for Related Library Features** - More sophisticated support library classes may depend on one or more additional support library classes, so you should use support library classes for those dependencies. For example, the [ViewPager](/reference/androidx/viewpager/widget/ViewPager) support class should be used with [FragmentPagerAdapter](/reference/androidx/fragment/app/FragmentPagerAdapter) or the [FragmentStatePagerAdapter](/reference/androidx/fragment/app/FragmentStatePagerAdapter) support classes.\n- **General Device Compatibility** - If you do not have a specific platform feature you intend to use with your app in a backward compatible way, it is still a good idea to use support library classes in your app. For example, you may want to use [ActivityCompat](/reference/androidx/core/app/ActivityCompat) in place of the framework [Activity](/reference/android/app/Activity) class, so you can take advantage of newer features later on, such as incorporating the new permissions model introduced in Android 6.0 (API level 23).\n\n\nSupport Library classes that provide a compatible implementation of platform\nAPI classes may not be able to provide the full set of functionality\navailable in the latest release, due to the limitations of the host device\nplatform version. In these cases, Support Library classes are designed to\ndegrade gracefully, and may not provide the all the functionality or data of\nthe current, platform API. For this reason, you should review the reference\ndocumentation for the library classes and methods you use, and thoroughly\ntest on devices running the earliest version of the platform supported by\nyour app.\n\n\n**Note:** The support libraries do not provide equivalent\nclasses and methods for each framework API. In some cases, you may need to\nwrap a framework method call with an explicit SDK version check and provide\nalternative code to handle methods not available on a device. For more\ninformation on using version checks in your code, see [Supporting Different\nPlatform Versions](/training/basics/supporting-devices/platforms).\n\nVersion Support and Package Names\n---------------------------------\n\n\nSome of the Support Library packages have package names to indicate the\nminimum level of the API they originally supported,\nusing a v# notation, such as the\nsupport-v4 package. Starting with Support Library version 26.0.0 (released in\nJuly 2017), the minimum supported API level has changed to Android 4.0 (API\nlevel 14) for all support library packages. For this reason, when working with\nany recent release of the support library, you should not assume that the\nthe *v#* package notation indicates a minimum API support level.\nThis change in recent releases also means that library packages with the v4\nand v7 are essentially equivalent in the minimum level of API they support.\nFor example, the support-v4 and the support-v7 package both support a minimum\nAPI level of 14, for releases of the Support Library from 26.0.0 and higher.\n\n### Support Library Release Versions\n\n\nThe [release version](/topic/libraries/support-library/revisions) of the Support Library, such as 24.2.0 or 25.0.1, is\ndifferent from the minimum API level supported by any library in that\nrelease.The release version number indicates which version of the platform\nAPI it was built against, and therefore, what the most recent APIs *may be\nincluded* in this version of the libraries.\n\n\nSpecifically, the first section of the release version number, for example\nthe 24 in version 24.2.0, generally corresponds with the version of the\nplatform API available when it was released. The release version level of the\nsupport library indicates it incorporates *some* features of that API\nlevel, but you should not assume it provides compatibility with *all*\nfeatures released in the new platform API version.\n\nLibrary Dependencies\n--------------------\n\n\nMost libraries in the Android Support Library suite have some dependency on\none or more libraries. For example, nearly all support libraries have a\ndependency on the `support-compat` package. In general, you do not\nneed to worry about support library dependencies, because the gradle build\ntool manages library dependencies for you, by automatically including\ndependent libraries.\n\n\nIf you want to see what libraries and library dependencies are included in\nyour app, run the following command at the build root of your app development\nproject to get a report of the dependencies for that project, including\nAndroid Support Libraries and other libraries: \n\n```\ngradle -q dependencies your-app-project:dependencies\n```\n\n\nFor more information about adding support libraries to your development\nproject using Gradle, see [Support\nLibrary Setup](/topic/libraries/support-library/setup). For more information about working with Gradle, see\n[Configure\nYour Build](/studio/build).\n\n\nNote that *all* Android Support Libraries also depend on some base level\nof the platform, for recent releases, that is Android 4.0 (API level 14) or\nhigher."]]