gpt4 book ai didi

android - 抽屉导航 : Gmail vs AppCompatv7 v21

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:37:03 26 4
gpt4 key购买 nike

我正在尝试将我的抽屉导航更改为类似于新 Gmail 应用程序的抽屉导航。我正在使用 AppCompatv7 - v21,并且有更新的 sdk。我错过了什么?请引用下面的图片。

Gmail 导航:

enter image description here

抽屉导航,移到工具栏上。

我当前的导航:

enter image description here

抽屉导航,位于工具栏下方。

[编辑]

这是我之前的 XML 代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<include
android:id="@+id/toolbar"
layout="@layout/toolbar_with_spinner" />

<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>

<ListView
android:id="@+id/listview_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/dark_grey"
android:choiceMode="singleChoice"
android:divider="@drawable/drawer_list_divider"
android:dividerHeight="2dp" />
</android.support.v4.widget.DrawerLayout>

</LinearLayout>

现在根据 pedro 的建议,我尝试将工具栏移动到 drawerlayout 中。

这是我的新 xml:

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

<include
android:id="@+id/toolbar"
layout="@layout/toolbar_with_spinner" />

<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>

<ListView
android:id="@+id/listview_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white"
android:choiceMode="singleChoice"
android:divider="@drawable/drawer_list_divider"
android:dividerHeight="2dp" />

</android.support.v4.widget.DrawerLayout>

这是我当前在 onCreate() 中的代码

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
toolbar = (Toolbar) findViewById(R.id.toolbar);
spinner = (Spinner) toolbar.findViewById(R.id.spinner);
mDrawerList = (ListView) findViewById(R.id.listview_drawer);

现在,我什至看不到工具栏。这是图片。

enter image description here

[编辑]

这是我的新布局。这行得通...再次感谢佩德罗...

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<include
android:id="@+id/toolbar"
layout="@layout/toolbar_with_spinner" />

<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>

<ListView
android:id="@+id/listview_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white"
android:choiceMode="singleChoice"
android:divider="@drawable/drawer_list_divider"
android:dividerHeight="2dp" />

</android.support.v4.widget.DrawerLayout>

enter image description here

最佳答案

您必须将工具栏放在抽屉布局中。

这是一个 XML 示例 from this Github Project:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include
android:id="@+id/toolbar_actionbar"
layout="@layout/toolbar_default"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<!-- android:layout_marginTop="?android:attr/actionBarSize"-->
<fragment
android:id="@+id/fragment_drawer"
android:name="com.poliveira.apps.materialtests.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>

关于android - 抽屉导航 : Gmail vs AppCompatv7 v21,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26885267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com