android ToolBar與DrawerLayout筆記,toolbardrawerlayout

來源:互聯網
上載者:User

android ToolBar與DrawerLayout筆記,toolbardrawerlayout

通過Android Studio 產生的Nagvition DrawerLayout Activity 內建的布局中的NagvitionView會覆蓋ToolBar直接通到statusBar。

但是自己想把NagvationView控制到TooBar下邊,從網上找到的答案是把ToolBar從CoordinatorLayout裡邊移出來,然後

主布局檔案:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical">    <android.support.v7.widget.Toolbar        android:id="@+id/toolbar"        android:layout_width="match_parent"        android:layout_height="?attr/actionBarSize"        android:background="?attr/colorPrimaryDark"        />    <android.support.v4.widget.DrawerLayout        android:id="@+id/drawer_layout"        android:layout_width="match_parent"        android:layout_height="match_parent">        <include            layout="@layout/app_bar_main"            android:layout_width="match_parent"            android:layout_height="match_parent" />        <android.support.design.widget.NavigationView            android:id="@+id/nav_view"            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:layout_gravity="start"            app:menu="@menu/activity_main_drawer" />    </android.support.v4.widget.DrawerLayout></LinearLayout>

這樣就會可以了,但是發現Tool會產生異樣的效果如:

其實是CoordinatorLayout的屬性設定成了android:fitsSystemWindows="true",把這個屬性去掉就好了。

app_bar_main布局:

 1 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 2     xmlns:tools="http://schemas.android.com/tools" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" 5      android:fitsSystemWindows="true"    <!--去掉這一句-->     6     tools:context="com.mmmmar.box.MainActivity"> 7  8     <include layout="@layout/content_main" /><!--你自己的布局--> 9 10     <android.support.design.widget.FloatingActionButton11         android:id="@+id/fab"12         android:layout_width="wrap_content"13         android:layout_height="wrap_content"14         android:layout_gravity="bottom|end"15         android:layout_margin="@dimen/fab_margin"16         android:src="@android:drawable/ic_dialog_email" />17 18 </android.support.design.widget.CoordinatorLayout>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.