使用v4 Fragments API实现ActionBar选项卡

时间:2022-01-20 15:21:43

My app is currently using the Fragments/v4 compatibility package to support Android versions all the way down to 1.6. This means all my Fragments inherit from the compatibility package's version of Fragment. I'm currently trying to rework parts of the app to take advantage of Honeycomb features, like ActionBar.

我的应用程序目前正在使用Fragments / v4兼容包来支持Android版本,一直到1.6。这意味着我的所有片段都从兼容包的Fragment版本继承。我目前正在尝试重做部分应用程序以利用Honeycomb功能,例如ActionBar。

I already use my own action-bar-like implementation on pre-3.0 devices, and the Honeycomb Action Bar otherwise. This bit isn't an issue.

我已经在3.0之前的设备上使用了我自己的动作栏实现,否则就使用了Honeycomb Action Bar。这个位不是问题。

The problem I have is trying to implement tabs using the ActionBar. ActionBar.TabListener expects the native Fragment and FragmentTransaction classes to work - so trying to use my Fragment classes (which inherit from the compatibility library) doesn't compile.

我遇到的问题是尝试使用ActionBar实现制表符。 ActionBar.TabListener期望本机Fragment和FragmentTransaction类工作 - 因此尝试使用我的Fragment类(从兼容性库继承)不会编译。

So, does anyone have any ideas how I can use fragments that use the compatibility package version of Fragment with ActionBar tabs?

那么,有没有人有任何想法如何使用Fragment与ActionBar选项卡的兼容包版本的片段?

tldr: how can I use ActionBar tabs with fragments that inherit from the v4 compatibility library?

tldr:如何将ActionBar选项卡与从v4兼容性库继承的片段一起使用?

1 个解决方案

#1


15  

I asked this question on the android-developers mailing list.

我在android-developers邮件列表上问了这个问题。

The approach I've taken is the one suggested by CommonsWare, whereby the provided FragmentTransaction parameter is ignored entirely: http://groups.google.com/group/android-developers/msg/d8d84cdd2f753b71

我采用的方法是CommonsWare建议的方法,其中提供的FragmentTransaction参数完全被忽略:http://groups.google.com/group/android-developers/msg/d8d84cdd2f753b71

#1


15  

I asked this question on the android-developers mailing list.

我在android-developers邮件列表上问了这个问题。

The approach I've taken is the one suggested by CommonsWare, whereby the provided FragmentTransaction parameter is ignored entirely: http://groups.google.com/group/android-developers/msg/d8d84cdd2f753b71

我采用的方法是CommonsWare建议的方法,其中提供的FragmentTransaction参数完全被忽略:http://groups.google.com/group/android-developers/msg/d8d84cdd2f753b71