Android:NavigationDrawer 和 ActionBarCompat [英] Android: NavigationDrawer and ActionBarCompat

查看:18
本文介绍了Android:NavigationDrawer 和 ActionBarCompat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用 ActionBarSherlockNavigationDrawer 合作,并取得了不错的效果,但我的公司不太可能很快批准这个开源,所以我正在努力切换到 ActionBarCompat.

I started working with NavigationDrawer using ActionBarSherlock and got good results, but my company approving this Open Source is not likely to come anytime soon, so I'm working to switch to ActionBarCompat.

ActionBarCompat 昨天(2013 年 7 月 24 日)刚刚正式发布.有没有人让两者都能很好地合作?我希望我能回答我自己的问题,但看看是否有人让这个工作.比赛开始了!:-)

ActionBarCompat was just officially released yesterday (July 24th, 2013). Has anyone gotten both to work well with each other? I'm hoping I can answer my own question, but seeing if anyone has gotten this to work. The race is on! :-)

YouTube 上 ActionBarCompat 的发布:https://www.youtube.com/watch?v=6TGgYqfJnyc

更新(工作代码,是的!):我已将 Google 的示例 NavigationDrawer 应用程序转换为使用 ActionBarCompat 并且运行良好.您可以在这里找到它作为参考或开始您的项目:https://github.com/bcrider/NavigationDrawerActionBarCompat

UPDATE (working code, yes!): I've gotten the sample NavigationDrawer app from Google converted to use ActionBarCompat and it is working fine. You can find it here as a reference or start to your project: https://github.com/bcrider/NavigationDrawerActionBarCompat

2.x 版本看起来比使用 ActionBarSherlock 的方式更好,但我必须更多地使用 ActionBarCompat 才能确定我是否更喜欢它.

The 2.x version looks even better than the way it did with ActionBarSherlock, but I'll have to work with ActionBarCompat a lot more to see if I like it better.

推荐答案

注意:我太新了,无法在帖子中添加多个链接等,所以我回答我自己的问题而不是编辑它(希望这是不违反规则?).一旦允许,将编辑原件.

NOTE: I'm too new to add more than one link in a post, etc., so am answering my own question instead of editing it (hope that's not against the rules?). Will edit the original once allowed.

使用 ActionBarCompat 添加导航抽屉的简单方法:我发现转换我现有的应用程序并没有我想象的那么糟糕.Google 的样本让我相信 Fragments 是必需品,但事实并非如此……远非如此.

Simple way to add Navigation Drawer with ActionBarCompat: I found that converting my existing app wasn't as bad as I thought it was going to be. Google's sample led me to believe Fragments were a necessity but that wasn't the case... far from it.

您可以简单地使用 DrawerLayout 包装现有布局并插入 ListView(或任何包含 ListView 的布局)以进行实际导航.然后将普通代码添加到您现有的 Activity(扩展 ActionBarActivity)并按照您必须的方式构建导航.

You can simply wrap your existing layouts with the DrawerLayout and plug in the ListView (or any layout containing the ListView for that matter) for the actual navigation. Then add the normal code to your existing Activity (extend ActionBarActivity) and build the navigation as you would have to anyway.

以下是一些用于包装现有布局的示例代码:

Here's some sample code with which to wrap your existing layout:

<?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

If you want to start with a sample app that does use fragments and go from there, here's my github repository based on the sample code: https://github.com/bcrider/NavigationDrawerActionBarCompat

这篇关于Android:NavigationDrawer 和 ActionBarCompat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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