我知道 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
并使用已弃用的 showDialog
和 onCreateDialog
在 API 级别 <11
Activity
类的方法
正如我已经说过的,恕我直言,最好的解决方案如下,但是(如果我错了请纠正我)这不是一个可能的解决方案:
3) 在 API 级别 11 或更高级别上运行时使用新的 android.app.DialogFragment
类并使用 android.support.v4.app。在 API 级别 < 11
如果我造成了一些困惑,我很抱歉,我希望这个问题很清楚..
最佳答案
当你在你的项目中使用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/