如何使用导航抽屉无碎片? [英] How can I use the Navigation Drawer without fragments?

查看:149
本文介绍了如何使用导航抽屉无碎片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按照这个教程如何创建一个抽屉式导航栏,但我不希望使用的片段显示给用户后,新的内容从抽屉列表中选择一项。什么是最好的形式给出,以解决这个问题? 我使用的是API 10不执行片段。

I'm trying to follow this tutorial on how to create a Navigation Drawer, but I don't want to use Fragments to show new content after the user select an item from the drawer list. What's the best aproach to get around this problem? I'm using API 10 which doesn't implements Fragments.

推荐答案

首先,API 10具有通过包含 DrawerLayout 同样支持Android包访问片段。这已经有两年多了,你不应该试图乱用像新事物DrawerLayout 如果你不熟悉什么Android已经过了近两年。

First, API 10 has access to fragments via the same Android Support package that contains the DrawerLayout. This has been around for over two years, and you should not be trying to mess with new things like DrawerLayout if you are unfamiliar with what Android has had for the past two years.

二,有什么用 DrawerLayout 被绑定到片段。引用<一href="https://developer.android.com/training/implementing-navigation/nav-drawer.html#ListItemClicks">the你链接到的网页:

Second, there is nothing with DrawerLayout that is tied to fragments. Quoting the Web page that you linked to:

当用户选择在抽屉里的列表中的项目,系统调用onItemClick()的()给setOnItemClickListener的OnItemClickListener。你在onItemClick()方法做取决于你如何实现你的应用程序结构。

When the user selects an item in the drawer's list, the system calls onItemClick() on the OnItemClickListener given to setOnItemClickListener(). What you do in the onItemClick() method depends on how you've implemented your app structure.

如果你仔细阅读这两句话,你会看到这个词碎片出现在他们都没有。这是因为 DrawerLayout 不依赖于片段。样品code,他们表现出使用了碎片,但仅仅是样品code。

If you read those two sentences closely, you will see that the word "fragment" appears in neither of them. That is because DrawerLayout is not tied to fragments. The sample code they show uses fragments, but that is merely sample code.

因此​​,欢迎你来更新你的用户界面,但是你想要的:

Hence, you are welcome to update your UI however you want:

  • 执行 FragmentTransaction 用碎片的支持Android包的反向移植,或
  • 在开始活动,或
  • 呼叫的setContentView()再次对现有的活动,或
  • ,否则修改​​现有活动的用户界面(例如,隐藏/显示一些小工具)
  • execute a FragmentTransaction using the Android Support package's backport of fragments, or
  • start an activity, or
  • call setContentView() again on your existing activity, or
  • otherwise modify the UI of the existing activity (e.g., hide/show some widgets)

这篇关于如何使用导航抽屉无碎片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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