android - v4 支持库是否在可用时使用新类?

标签 android android-fragments android-support-library android-dialogfragment

我知道 v4 支持库可用于在较新版本中引入的旧 android 版本中实现某些功能,例如 Fragments。如果我们实现一个使用 < em>v4 支持库来显示对话框 fragment ,例如,它在 ICS 上运行时是否使用最新的代码(即原始和更新的 fragment ),还是仍然使用支持每个android版本的代码?

有没有办法在同一个应用程序中同时使用 android.app.Fragment 类和 android.support.v4.app.Fragment 类,区别在于如果我们运行在 支持 fragment 的版本 上运行,或者我们在导入 v4 支持库 时是否只需要使用支持类?

也许我错了,但在我看来,在最近的平台上运行时不使用最新的代码并不是一个好主意。

坚持Dialog Fragment案例,你认为哪个更好:

1)使用v4支持库,即在所有android版本上使用兼容代码

2) 在 API 级别 11 或更高级别上运行时使用新的 android.app.DialogFragment 并使用已弃用的 showDialogonCreateDialog 在 API 级别 <11

上运行时 Activity 类的方法

正如我已经说过的,恕我直言,最好的解决方案如下,但是(如果我错了请纠正我)这不是一个可能的解决方案:

3) 在 API 级别 11 或更高级别上运行时使用新的 android.app.DialogFragment 类并使用 android.support.v4.app。在 API 级别 < 11

上运行时的 DialogFragment

如果我造成了一些困惑,我很抱歉,我希望这个问题很清楚..

最佳答案

当你在你的项目中使用android support libary时,即使设备具有兼容Android的API级别,因此它不需要使用兼容库,它仍然会使用compatibillity库中的方法。

编辑

浏览它声明的 Android 支持库 v4 代码(在 android.support.v4.app.Fragment 类的注释中):

Static library support version of the framework's android.app.Fragment. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.

链接 here .

关于android - v4 支持库是否在可用时使用新类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11263533/

相关文章:

android - Web 服务的最佳 RESTful 方法

android - cursor.moveToNext() 抛出 CursorWindowAllocationException

android - 如何使 DialogFragment 宽度为 Fill_Parent

android - 对话 fragment : NullPointerException (support library)

android - 支持库 23.2.0 中的 CoordinatorLayout IllegalStateException

java - Gradle:com.android.support:support-compat:25.3.1 和 com.android.support:animated-vector-drawable:24.0.0 必须使用完全相同的版本

android - 通过通知向 pendingIntent 发送不同的参数

android - 如何在 Android 中使用 Intent 启动闹钟屏幕?

Android Fragment 生命周期方向改变

android - 调用 findViewById() 获取 fragment View 时出现 NullPointerException