ActionBarSherlock 和 ActionBar 兼容性之间的差异

发布于 2024-12-11 06:40:35 字数 515 浏览 0 评论 0原文

ActionBarSherlockAction Bar 兼容性

几天前,Google 刚刚发布了 ActionBar 兼容性,这让我很困惑。 Action Bar Compatibility 的工作原理与 ActionBarSherlock 相同并且编码相同吗?

示例:应用图标是否可以“向上”导航 或 ActionBar.Tab 在操作栏兼容性中受支持吗?

What is the difference between ActionBarSherlock and Action Bar Compatibility

Fews days ago Google just released the ActionBar Compatibility that make me so confused. Is that the Action Bar Compatibility works same as the ActionBarSherlock and is the coding same?

Example : Does app icon to navigate "up" or ActionBar.Tab supported in Action Bar Compatibility ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

海未深 2024-12-18 06:40:35

ActionBarSherlock 与 ActionBarCompat:

我只想在 ActionBarSherlock 与 ActionBarCompat Lib 之间添加一些代码差异

 ActionBarSherlock 与 ActionBarCompat * *strong text**

我们可以将一些应用程序从 ActionBarSherlock 迁移到 ActionBarCompat:

步骤:

  1. 导入AppCompat 项目。

  2. SherlockFragmentActivity替换为ActionBarActivity

  3. SherlockFragment替换为Fragment

  4. 更改 MenuMenuItemgetSupportMenuInflater() 引用。
    修改获取操作视图的方式。

    mSearchView = (SearchView)MenuItemCompat.getActionView(mSearchItem)

  5. 修改您的主题样式

如需了解更多信息,请参阅 +NickButcher (Google) 的幻灯片

在此处输入图像描述

感谢来源:
http://gmariotti.blogspot.in/2013/07/actionbarsherlock-vs-actionbarcompat.html< /a>
http://antonioleiva.com/actionbarcompat-migration-actionbarsherlock/

不要忘记阅读此内容developer.android 了解有关 ABC 的更多信息!

注意:遗憾的是,使用支持库无法以与 ABS 相同的方式将其设置为单元测试。

输出:

在此处输入图像描述

致谢:Gabriele Mariotti

ActionBarSherlock vs ActionBarCompat:

I Just want to put few code difference between ActionBarSherlock vs ActionBarCompat Lib

 ActionBarSherlock vs ActionBarCompat **strong text**

We can migrate some apps from ActionBarSherlock to ActionBarCompat:

steps:

  1. Import AppCompat project.

  2. Replace SherlockFragmentActivity with ActionBarActivity.

  3. Replace SherlockFragment with Fragment.

  4. Change Menu, MenuItem and getSupportMenuInflater() references.
    Modify the way you get Action Views.

    mSearchView = (SearchView)MenuItemCompat.getActionView(mSearchItem)

  5. Modify your Themes and Styles.

For more info, please refer this slides by +NickButcher (Google)

enter image description here

Thanks to Sources:
http://gmariotti.blogspot.in/2013/07/actionbarsherlock-vs-actionbarcompat.html
http://antonioleiva.com/actionbarcompat-migrating-actionbarsherlock/

Don't forget to read this developer.android for more about ABC!

Note: Setting it up for unit tests the same way as ABS is unfortunately not possible with the support library.

Output:

enter image description here

Credits: Gabriele Mariotti

眉黛浅 2024-12-18 06:40:35

ActionBarSherlock 为您的应用程序提供一个操作栏,无论*您的应用程序运行在哪个版本的 Android API 上。仅当您运行的设备为 API 级别 3.0 或更高版本时,操作栏兼容性才会为您提供操作栏。

*请注意,如果您运行的设备不是 3.0 或更高版本,ActionBarSherlock 将使用它自己的操作栏自定义实现,而不是本机实现。

--编辑--

事情似乎已经发生了变化,实际上 ActionBarSherlock 和操作栏兼容性之间不再有任何区别。请阅读下面的评论了解详细信息。

--编辑--

现在使用两者之后,我可以说我实际上更喜欢 ActionBarSherlock 而不是 Action Bar Compatibility。 ActionBarSherlock 确实简单易用。

- 编辑 -
正如 LOG_TAG 提到的,Android 支持库现在支持操作栏。我还没有机会使用它,但我想这是最好的使用方式。

ActionBarSherlock gives your application an action bar regardless* of what version of the android API your app is being run on. Action Bar Compatibility gives you the action bar only if the device that you're running on is API level 3.0 or above.

*Note that if the device you're running on isn't 3.0 or above, ActionBarSherlock is going to use it's own custom implementation of the action bar, not a native one.

--EDIT--

It appears things have changed and there is actually no difference between ActionBarSherlock and the Action Bar Compatibility anymore. Please read the comments below for details.

--EDIT--

After having used both now, I can say that I actually prefer ActionBarSherlock to Action Bar Compatibility. ActionBarSherlock is really easy and nice to use.

--EDIT--
As LOG_TAG mentioned, there is now support for the action bar in the Android Support Library. I haven't had a chance to use it yet, but I would imagine that's the best one to use.

左岸枫 2024-12-18 06:40:35

只是用一个实际的例子来完成@Kurtis Nusbaum 的内容。

更新:正如@rudy-s所说,通过最新的android支持库(api 18),我看到他们已经内置了对actionbar的支持(称为ActionBarCompat类)。

我构建了两个简单的应用程序来展示 ActionBarSherlock 和 ActionBar Compatibility 之间的视觉差异。请参阅比较图像:

使用兼容性库的应用程序

使用 sherlock 库的应用程序

现在按下菜单按钮时的外观:

在按下菜单时使用兼容性的应用程序

<图片src="https://i.sstatic.net/KgcXQ.png" alt="应用程序在菜单上使用 sherlock 按下">


如您所见,图像只是强制执行所说的内容。 仅当您运行的设备为 API 级别 3.0 或更高版本时,操作栏兼容性才会为您提供操作栏。而 Sherlock 则更通用。

下面你可以看到应用程序源码。

菜单 xml 文件是相同的:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@+id/action_1"
    android:orderInCategory="100"
    android:showAsAction="always"
    android:title="@string/action1"/>

<item
    android:id="@+id/action_2"
    android:orderInCategory="100"
    android:showAsAction="ifRoom"
    android:title="@string/action2"/>

<item
    android:id="@+id/action_3"
    android:orderInCategory="100"
    android:showAsAction="ifRoom"
    android:title="@string/action3"/>

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>

</menu>

兼容性的活动:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
     }

     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
     }
}

Sherlock 的活动:

public class MainActivity extends SherlockActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
        getSupportMenuInflater().inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);
    }

}

sherlock 应用程序需要额外的配置:

更新:
正如@rudy-s所说,通过最新的android支持库(api 18),我看到他们已经内置了对actionbar的支持(称为ActionBarCompat类)。

Just completing what @Kurtis Nusbaum with a pratical example.

UPDATE: as @rudy-s said, with newest android support library (api 18), I saw they already have built-in support for actionbar (called ActionBarCompat class).

I built two simple applications to show the visual difference between ActionBarSherlock and ActionBar Compatibility. See the comparatives images:

App using compatibility library

App using sherlock library

Now the appearance when the menu button is pressed:

App using compatibility on menu pressed

App using sherlock on menu pressed


As you can see, the images just enforce what was said. Action Bar Compatibility gives you the action bar only if the device that you're running on is API level 3.0 or above. While Sherlock is more general.

Below you can see the application source.

The menu xml file is the same:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@+id/action_1"
    android:orderInCategory="100"
    android:showAsAction="always"
    android:title="@string/action1"/>

<item
    android:id="@+id/action_2"
    android:orderInCategory="100"
    android:showAsAction="ifRoom"
    android:title="@string/action2"/>

<item
    android:id="@+id/action_3"
    android:orderInCategory="100"
    android:showAsAction="ifRoom"
    android:title="@string/action3"/>

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>

</menu>

Compatibility's activity:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
     }

     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
     }
}

Sherlock's activity:

public class MainActivity extends SherlockActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
        getSupportMenuInflater().inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);
    }

}

An additional config was necessary on sherlock app:

<style name="AppBaseTheme" parent="Theme.Sherlock.Light.DarkActionBar">

UPDATE:
as @rudy-s said, with newest android support library (api 18), I saw they already have built-in support for actionbar (called ActionBarCompat class).

木有鱼丸 2024-12-18 06:40:35

Actionbar Sherlock 比简单的 Actionbar 兼容性项目更先进、更雄心勃勃。

如果您只想在应用程序顶部添加操作栏,则操作栏兼容性可以被视为“示例”或一个很好的起点。

ActionBarSherlock 基于兼容性库构建,并为您提供(如操作栏兼容性示例)3.0 之前的设备上的操作栏。此外,它还具有 ActionBar Compat 代码中不存在的额外功能。这包括但不限于

  • setNavigationMode(用于操作栏中的选项卡和微调器)
  • 等功能对话框片段
  • 上下文操作栏 (CAB) 接管操作栏的菜单,例如用于多选 (http://developer. android.com/design/patterns/new-4-0.html)这是一个 ICS 功能(!)为此,必须将 ActionMode 类(在 API 级别 11 中引入)的实现引入到ActionbarSherlock 库
  • Fragment 和 FragmentActivity 实现 - 因为 Fragment 可以实现 onCreateOptions 菜单,所以我们需要确保使用了 SupportMenuInflater。
  • 两个主题与 Holo.Dark 和 Holo.Light 不太相似(Theme.Sherlock、Theme.Sherlock.Light)
  • ICS 功能“分割操作栏”

我认为使用 ActionbarSherlock 的唯一缺点是您将自己锁定在该库中。如果由于某种原因它将在不久的将来消失,您将必须自己维护它(例如,如果没有 Jellybean 实现)。这是一个麻烦(不是一个大问题),因为您的所有片段都扩展了 SherlockFragemnt 和您的所有活动。
夏洛克活动。

Actionbar Sherlock is far more advanced and far more ambitious than the simple Actionbar compatibility project.

The Action bar compatibility can be considered a "sample" or a good starting point if you only want to smack an Action Bar on top of your app.

ActionBarSherlock builds on the compatibility library, and gives you (like the action bar compatibility sample) an Action Bar on pre-3.0 devices. In addition it has extra features not present in the ActionBar Compat code. This includes features like, but not limited to

  • setNavigationMode (for Tabs and spinners in the action bar)
  • Dialog Fragments
  • Contextual Action Bar (CAB) a menu that takes over the action bar, used for example for multi select (http://developer.android.com/design/patterns/new-4-0.html) This is a ICS feature (!) For this, an implementation of the ActionMode class (introduced in API level 11) had to be introduced into the ActionbarSherlock library
  • Fragment and FragmentActivity implementations - because fragments can implement the onCreateOptions menu, we need to make sure that the SupportMenuInflater is used.
  • Two themes not very unlike Holo.Dark and Holo.Light (Theme.Sherlock, Theme.Sherlock.Light)
  • The ICS feature "split action bar"

The only downside I see in using ActionbarSherlock is that you lock yourself in to that library. If for some reason it will die out in the near future, you'll have to maintain it youself (for example if no Jellybean implementation comes along). This is a hassle (not a huge problem) since all your fragments extends SherlockFragemnt and all your Activities.
SherlockActivity.

鱼窥荷 2024-12-18 06:40:35

@Jake 实现比 Actionbar compat 走得更远,更准确地说,Actionbar Compat 只是一个基本示例,说明如何使用 Honeycomb (API 13) 之前的版本的伪操作栏支持所有应用程序。尽管他们的目标是相同的交叉兼容操作栏,但他们有不同的方法。

ActionbarCompat 方法

此实现不使用兼容性 Android 支持库,而是创建一个名为 ActionBarActivity 创建 Helper 这个助手充当工厂本身返回 APIS 三个部分的不同实现,它返回

  • ActionbarBaseHelper:适用于 HoneyComb 之前的版本。
  • ActionBarHoneyComb:用于 HoneyComb
  • <一个href="http://developer.android.com/resources/samples/ActionBarCompat/src/com/example/android/actionbarcompat/ActionBarHelperICS.html" rel="noreferrer">ActionBarHelperICS:适用于 ICS 基础设备。

最有趣的部分是 ActionbarBaseHelper< /a>,因为它有最重要的代码,我建议你理解这个类,你就会得到整个例子。

Action Bar Sherlock

嗯,这首先很棘手,因为我不是作者,也许杰克可以进一步解释这一点,但我会尝试一下。

正如 compat Sherlock 做了不同的实现,但一个是“Compat”,另一个是 Native。它强制您从 SherlockActivity 或 SherlockFragmentActivity 进行扩展,因为这两个基类具有调度 ActionBar 的方法。

这是一个庞大而复杂的项目,不可能在一篇文章中解释清楚。建议您深入探索 Sherlock Github 存储库 看一下,然后 杰夫·阿特伍德

在此处输入图像描述

Well @Jake implementation goes way further than what the Actionbar compat, to be more precise Actionbar Compat is just a basic example on how can you support all aplication with a pseudo-actionbar for releases prior from Honeycomb (API 13). Although their target is the same cross compatible actionbar, they have diferent approach.

ActionbarCompat Aproach

This implementation make no use of the Compatibility Android support library instead it create a base class called ActionBarActivity create a single instance of a Helper this helper act as factory itself that returns diferent implementation for the three segment of APIS, it returns

The most interesting part is in the ActionbarBaseHelper, because it has the most important code, I suggest you understand this class and you will get the whole example.

Action Bar Sherlock

Well this is tricky firstable because, I'm not the author maybe Jake can explained further this, but I'll give it a try.

Just as the compat Sherlock make diferent implementation but one is for "Compat" and the other is Native. It force you to extends either from SherlockActivity or from SherlockFragmentActivity, because this two base classes have the method for dispatching the ActionBar.

This is a large and complex project, that cannot be explained in a single post. Suggest you dig around Sherlock Github repo grab a look and as Jeff Atwood says

enter image description here

酒儿 2024-12-18 06:40:35
  • 我坚信您应该为所有新内容使用 ActionBarCompat
    想要支持旧设备的项目。

  • 迁移现有项目也可能有意义。所以请继续阅读
    了解为什么您应该立即迁移或使用 ActionBarCompat 以及
    如何迁移现有项目。

为什么您应该更喜欢 ActionBarCompat 而不是 ActionBarSherlock?

为什么您应该更喜欢 ActionbarCompat 而不是 ActionbarSherlock 有很多原因。

  1. 首先,这个项目是由 Google 开发的,是支持的一部分
    库,因此可能会支持新的操作栏相关内容
    与此同时,Google 还通过原生 Android 发布了它们。

  2. 另一个很好的理由是它支持导航抽屉
    模式
    开箱即用,而 ActionBarSherlock 则不然。因此
    如果您想将此抽屉添加到现有项目/应用程序中,您应该
    迁移。

  3. 最后也是重要的是,ActionBarSherlock 的创建者,
    杰克·沃顿 (Jake Wharton) 在 Google+ 上宣布进一步开发
    ActionBarSherlock 已停止。 ActionBarSherlock 4.4 是
    最新版本,可能会修复错误 - 但不会有任何新的
    功能:因此,如果操作栏中包含新功能,您可以
    最后一点也是重要的是, ActionBarSherlock

  • I strongly believe that you should use ActionBarCompat for all new
    projects that want to support older devices.

  • It also might make sense to migrate existing projects. So read on to
    learn why you should migrate or use ActionBarCompat right away and
    how to migrate existing projects.

Why you should prefer ActionBarCompat over ActionBarSherlock?

There are many reasons why you should prefer ActionbarCompat over ActionbarSherlock.

  1. First of all this project is by Google, is part of the Support
    Library and thus likely will support new Action Bar related stuff at
    the same time Google releases them with stock Android.

  2. Another good reason is that it supports the Navigation Drawer
    pattern
    right out of the box, while ActionBarSherlock does not. Thus
    if you want to add this drawer to an existing project/app you should
    migrate.

  3. The last and Important is, that the creator of ActionBarSherlock,
    Jake Wharton, announced on Google+ that further development of
    ActionBarSherlock has been stopped. ActionBarSherlock 4.4 is the
    last release and might get bug fixes – but there won’t be any new
    features: So if new functionality is included in actionbar you may
    not keep up to it with actionbarsherlock.

南薇 2024-12-18 06:40:35

也许我们应该更新答案,因为谷歌自 API18

下面的块来自官方博客 关于这两个库:

如果您使用第三方解决方案(例如 ActionBarSherlock),有几个理由需要考虑升级:

  • 可以随着 Action Bar API 的发展而不断更新。
  • 集成祖先导航支持。
  • 使用框架 Menu 和 MenuItem 类。
  • 继续使用支持库的 Fragment 类。
  • 集成了对 ActionBarDrawerToggle 的支持,以便与 DrawerLayout 一起使用。
  • PopupMenu 的向后移植。

ActionBarSherlock 是一个可靠且经过充分测试的库,长期以来一直为开发人员提供了良好的服务。如果您已经在使用它并且当前不需要上述任何内容,则无需迁移。

Maybe we should update the answer because google published offical Actionbar support since API18?

block below is from offical blog about these two libraries:

If you’re using a third-party solution (such as ActionBarSherlock), there are a few reasons to consider upgrading:

  • Can be kept updated as the Action Bar API evolves.
  • Integrated Ancestral Navigation support.
  • Use of framework Menu and MenuItem classes.
  • Continue to use the Support Library's Fragment class.
  • Integrated support for ActionBarDrawerToggle for use with DrawerLayout.
  • Backport of PopupMenu.

ActionBarSherlock is a solid and well-tested library which has served developers very well for a long time. If you are already using it and do not currently require any of the above then there is no need to migrate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文