Android快速開發_建立MaterialDesign風格架構

來源:互聯網
上載者:User

標籤:

建立左側滑動Drawer

步驟1:

依賴庫:
compile ‘com.android.support:appcompat-v7:23.1.1‘compile ‘com.android.support:design:23.1.1‘

 

步驟2: 

主介面布局使用 

android.support.v4.widget.DrawerLayout

 1 <?xml version="1.0" encoding="utf-8"?> 2 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     xmlns:app="http://schemas.android.com/apk/res-auto" 4     android:id="@+id/drawer" 5     android:layout_width="match_parent" 6     android:layout_height="match_parent" 7     android:fitsSystemWindows="true"> 8  9     <include layout="@layout/content_main"></include>10 11 12     <android.support.design.widget.NavigationView13         android:layout_width="match_parent"14         android:layout_height="match_parent"15         android:layout_gravity="start"16         android:fitsSystemWindows="true"17         app:headerLayout="@layout/nav_header"18         app:menu="@menu/drawer_view">19 20     </android.support.design.widget.NavigationView>21 </android.support.v4.widget.DrawerLayout>
View Code
步驟3:
1.建立左滑Drawer中的head部分布局,僅僅是一個linearlayout加上一個TextView
 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2     android:layout_width="match_parent" 3     android:layout_height="192dp" 4     android:background="?attr/colorPrimaryDark" 5     android:padding="16dp" 6     android:theme="@style/ThemeOverlay.AppCompat.Dark" 7     android:orientation="vertical" 8     android:gravity="bottom"> 9 10     <TextView11         android:layout_width="match_parent"12         android:layout_height="wrap_content"13         android:text="Username"14         android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>15 16 </LinearLayout>
View Code

 

2.建立左滑Drawer中的menu布局(注意這個布局是在menu菜單中寫的)
 1 <menu xmlns:android="http://schemas.android.com/apk/res/android"> 2  3     <group android:checkableBehavior="single"> 4         <item 5             android:id="@+id/nav_home" 6             android:icon="@drawable/ic_dashboard" 7             android:title="Home" /> 8         <item 9             android:id="@+id/nav_messages"10             android:icon="@drawable/ic_event"11             android:title="Messages" />12         <item13             android:id="@+id/nav_friends"14             android:icon="@drawable/ic_headset"15             android:title="Friends" />16         <item17             android:id="@+id/nav_discussion"18             android:icon="@drawable/ic_forum"19             android:title="Discussion" />20     </group>21 22     <item android:title="Sub items">23         <menu>24             <item25                 android:icon="@drawable/ic_dashboard"26                 android:title="Sub item 1" />27             <item28                 android:icon="@drawable/ic_forum"29                 android:title="Sub item 2" />30         </menu>31     </item>32 33 </menu>
View Code

 

左滑Drawer Down!




Android快速開發_建立MaterialDesign風格架構

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.