How can I use the Navigation Drawer without fragments?

后端 未结 4 1061
不思量自难忘°
不思量自难忘° 2021-02-06 02:32

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 li

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 03:11

    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.

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

    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.

    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:

    • 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)

提交回复
热议问题