android.app.Fragment 和 android.support.v4.app.Fragment 的区别 [英] Difference between android.app.Fragment and android.support.v4.app.Fragment
问题描述
android.app.Fragment
和 android.support.v4.app.Fragment
有什么区别,分别应该在什么情况下使用?
What is the difference between android.app.Fragment
and android.support.v4.app.Fragment
, and what are the circumstances in which each should be used?
推荐答案
android.support.v4.app.Fragment
是 Fragment 类,这是一个兼容包,允许您在Android 上使用一些较新的功能旧版本的 Android.
android.support.v4.app.Fragment
is the Fragment class in the android support library, which is a compatibility package that allows you to use some of the newer features of Android on older versions of Android.
android.app.Fragment
是 Fragment
android.app.Fragment
is the Fragment class in the native version of the Android SDK. It was introduced in Android 3 (API 11).
如果您想让您的应用使用 Fragment,并希望针对 API 11 之前的设备,您必须使用 android.support.v4.app.Fragment
.但是,如果您只针对运行 API 11 或更高版本的设备,则可以使用 android.app.Fragment
.
If you want to make your app use fragments, and want to target devices before API 11, you must use android.support.v4.app.Fragment
. However, if you're only targeting devices running API 11 or above, you can use android.app.Fragment
.
操作系统包含的 android.app.Fragment
现已弃用(从 API 级别 28 开始),每个人都应该转而使用支持库实现.
the OS-contained android.app.Fragment
is now deprecated (as of API level 28), and everyone should move to using the support library implementations.
这篇关于android.app.Fragment 和 android.support.v4.app.Fragment 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!