zoukankan      html  css  js  c++  java
  • Android快速开发_建立MaterialDesign风格框架

    建立左侧滑动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.NavigationView
    13         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     <TextView
    11         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         <item
    13             android:id="@+id/nav_friends"
    14             android:icon="@drawable/ic_headset"
    15             android:title="Friends" />
    16         <item
    17             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             <item
    25                 android:icon="@drawable/ic_dashboard"
    26                 android:title="Sub item 1" />
    27             <item
    28                 android:icon="@drawable/ic_forum"
    29                 android:title="Sub item 2" />
    30         </menu>
    31     </item>
    32 
    33 </menu>
    View Code
    左滑Drawer Down!




    -----------------------------------------------------

    Github:

    https://github.com/RainFool
  • 相关阅读:
    The Collections Module内建collections集合模块
    生成器接受和返还功能在执行过程中的详解以及生成器实现协同
    写python中的装饰器
    windows下载Mysql-python
    分别用单线程和多线程运行斐波那契、阶乘和累加和
    TCP客户端和服务器间传输数据遇到的TypeError: a bytes-like object is required, not 'str'问题
    python的property属性
    python的伪私有属性
    使用栈实现中缀表达式转为后缀表达式和后缀表达式的求解
    公众帐号如何向用户发送emoji表情(php版,附emoji编码表)
  • 原文地址:https://www.cnblogs.com/RainFool/p/5052558.html
Copyright © 2011-2022 走看看