我开始与导航抽屉 using 动作栏夏洛克并取得了良好的结果,但我的公司不太可能很快批准这个开源,所以我正在努力切换到 ActionBarCompat。
ActionBar兼容昨天(2013年7月24日)刚刚正式发布。有人让两者能够很好地合作吗?我希望我能回答我自己的问题,但看看是否有人能做到这一点。比赛开始了! :-)
YouTube 关于 ActionBarCompat 的发布:
https://www.youtube.com/watch?v=6TGgYqfJnyc https://www.youtube.com/watch?v=6TGgYqfJnyc
更新(工作代码,是的!):我已经从 Google 获得了示例 NavigationDrawer 应用程序,并将其转换为使用 ActionBarCompat 并且工作正常。您可以在这里找到它作为参考或开始您的项目:https://github.com/bcrider/NavigationDrawerActionBarCompat https://github.com/bcrider/NavigationDrawerActionBarCompat
2.x 版本看起来甚至比 ActionBarSherlock 的效果更好,但我必须更多地使用 ActionBarCompat 来看看我是否更喜欢它。
注意:我太新了,无法在一篇文章等中添加多个链接,所以我回答我自己的问题而不是编辑它(希望这不违反规则?)。一旦允许,将编辑原始内容。
使用 ActionBarCompat 添加导航抽屉的简单方法:我发现转换现有应用程序并不像我想象的那么糟糕。谷歌的样本让我相信片段是必需的,但事实并非如此......远非如此。
您可以简单地使用 DrawerLayout 包装现有布局并插入 ListView(或任何包含 ListView 的布局)以进行实际导航。然后将普通代码添加到现有的 Activity(扩展 ActionBarActivity)并构建导航(无论如何)。
以下是一些用于包装现有布局的示例代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
[YOUR EXISTING LAYOUT GOES HERE]
<ListView
android:id="@+id/left_drawer"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>
如果您想从使用片段的示例应用程序开始并从那里开始,这里是我基于示例代码的 github 存储库:https://github.com/bcrider/NavigationDrawerActionBarCompat https://github.com/bcrider/NavigationDrawerActionBarCompat
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)