簡體   English   中英

導航抽屜:Gmail與AppCompatv7 v21

[英]Navigation Drawer: Gmail vs AppCompatv7 v21

我正在嘗試將導航抽屜更改為類似於新Gmail應用程序的導航抽屜。 我正在使用AppCompatv7-v21,並具有更新的SDK。 我想念的是什么? 請參考下面的圖片。

Gmail導航:

在此處輸入圖片說明

導航抽屜在工具欄上移動。

我當前的導航:

在此處輸入圖片說明

導航抽屜位於工具欄下方。

[編輯]

這是我以前的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的建議,我嘗試將工具欄移到抽屜布局內。

這是我的新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);

現在,我什至看不到工具欄。 這是圖片。

在此處輸入圖片說明

[編輯]

這是我的新布局。 這有效..再次感謝pedro ...

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

在此處輸入圖片說明

您必須將工具欄放在“抽屜布局”中。

這是從此Github項目中獲取的XML的示例

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

這是我的新布局。 這有效..再次感謝pedro ...

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

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM