操作栏在API级别> 3.0,但仍然支持API< 3.0 [英] Action Bar in API Level > 3.0 but Still Support API < 3.0

查看:115
本文介绍了操作栏在API级别> 3.0,但仍然支持API< 3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还有一个兼容性的问题。

Yet another compatibility question.

问题

我需要使用API​​级别3.0和更高的标签的操作栏片段之间切换。不过,我也需要能够为这些片段之间切换不知何故在API级< 3.0。

I need to use a tabbed action bar in api level 3.0 and greater to switch between fragments. However, I also need to be able to switch between these fragments somehow in api level < 3.0.

在作品中的扳手的是,我已经下载了一个自定义兼容性库,允许我使用 Google地图片段,所以我不能使用的库。

The spanner in the works is the fact that I have already downloaded a custom compatibility library that allows me to use google maps with fragments and therefore I can't use a library.

问题

我怎么能在3.0和更高的执行选项卡式动作条解决方案,也迎合了更大的市场是3.0,少?

How can I implement a tabbed ActionBar solution in 3.0 and greater and also cater for the bigger market that is 3.0 and less?

任何帮助将是盛大的。

推荐答案

于是我设法前一阵子图个解决方案,它只是我花了一段张贴在这里。

So I managed to figure a solution a while ago, it's just taken me a while to post it here.

这是对我的作品的解决方案。我需要使用一个动作条,但我还需要使用MapActivity以及FragmentActivity因此不能够使用ActionBarSherlock

This is the solution that works for me. I needed to use an ActionBar but I also needed to use the MapActivity as well as the FragmentActivity hence not being able to use ActionBarSherlock.

我所做的是以下内容:

  • 创建了一个名为CCActionBar片段处理的CCTab的感人通过增加自身作为监听器(下文解释)。它还膨胀布局称为动作barlayout其中有标签和排列的图像,只是参考的选项卡在运行时。

  • Created a fragment called CCActionBar which handles the touching of the CCTab's by adding itself as a listener(explained below). It also inflates a layout called action barlayout which has the tabs and images arranged, just reference the tabs at run time.

创建了一个名为CCTab的自定义视图,它重新present操作栏中的标签。当它触及它告诉它的监听器(CCActionBar)的被感动。

Created a custom view called CCTab which represent the tabs of the action bar. When its touched it tells its listener (CCActionBar) its been touched.

在我的主要布局文件中有我显示或在运行时隐藏取决于API层次上的操作杆的容器。

In my main layout xml file have an action bar container which I show or hide at runtime depending on the API level.

现在我在我的onCreate方法主要活动查询我的API级别是否大于3.0与否。如果是我刚刚实施的标准动作条,确保我的自定义操作栏容器是不可见的。如果没有设置我的自定义操作栏,并在我的XML布局肯定我的行动吧容器。

Now in my main activity in my OnCreate method I check whether my API level is greater than 3.0 or not. If it is I just implement the standard ActionBar making sure my custom action bar container is invisible. If it isn't I set up my custom action bar and make sure my action bar container in my xml layout is visible.

  • 然后,我要确保,当一个标签是pssed同时使用这两种方法是相同的方式处理,所以一旦其设置你不必处理它有什么不同$ P $。

我希望这可以帮助别人的地方,或者至少给你如何进行的想法。

I hope this helps someone somewhere or at least give you an idea of how to proceed.

这篇关于操作栏在API级别&GT; 3.0,但仍然支持API&LT; 3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆