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

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

问题描述

我开始工作的 NavigationDrawer 使用的 ActionBarSherlock ,并取得了很好的成绩,但我公司批准这项开源是不太可能很快到来,所以我努力切换到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的版本: <一href="https://www.youtube.com/watch?v=6TGgYqfJnyc">https://www.youtube.com/watch?v=6TGgYqfJnyc

更新(工作code,是的!): 我已经得到了样品NavigationDrawer应用程序从谷歌转换到使用ActionBarCompat,这是工作的罚款。你可以在这里找到它作为一个参考或者开始到项目中: <一href="https://github.com/bcrider/NavigationDrawerActionBarCompat">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: 我发现,将我现有的应用程序并没有那么糟糕,因为我认为这将是。谷歌的样品让我相信片段必要但情况并非如此......远非如此。

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为此事的任何布局)的实际导航。然后添加普通code到现有的活动(扩大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.

下面是一些示例code与包装现有的布局:

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>

如果你想开始一个样本应用程序,并使用碎片,并从那里走,这是我根据样本code GitHub的库:<一href="https://github.com/bcrider/NavigationDrawerActionBarCompat">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

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

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