美文网首页
Android基础13

Android基础13

作者: 毕丙伟 | 来源:发表于2017-07-24 09:45 被阅读0次

    MaterialDesign

    1. toolbar
    2. 侧边栏
    3. 悬浮按钮
    4. Snackbar

    toolbar
    布局文件
    res/values/styles.xml更改

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
        </style>
    
    <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="wrap_content"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:popupTheme="@style/ThemeOverlay.AppCompat.Light">
            </android.support.v7.widget.Toolbar>
    

    侧边栏
    布局文件

    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="com.example.bbw.materialdesigndemo.MainActivity">
    
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="wrap_content"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:popupTheme="@style/ThemeOverlay.AppCompat.Light">
            </android.support.v7.widget.Toolbar>
    
            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|end"
                android:layout_margin="16dp"
                android:src="@drawable/ic_done"
                android:elevation="8dp"/>
        </android.support.design.widget.CoordinatorLayout>
    
        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:menu="@menu/nav_menu"
            app:headerLayout="@layout/nav_header"/>
    
    </android.support.v4.widget.DrawerLayout>
    

    nav_menu

    <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android">
    
        <group android:checkableBehavior="single">
            <item
                android:id="@+id/nav_call"
                android:icon="@drawable/nav_call"
                android:title="call"/>
            <item
                android:id="@+id/nav_friends"
                android:icon="@drawable/nav_friends"
                android:title="friends"/>
            <item
                android:id="@+id/nav_location"
                android:icon="@drawable/nav_location"
                android:title="location"/>
            <item
                android:id="@+id/nav_mail"
                android:icon="@drawable/nav_mail"
                android:title="mail"/>
            <item
                android:id="@+id/nav_task"
                android:icon="@drawable/nav_task"
                android:title="task"/>
        </group>
    
    </menu>
    

    nav_header.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="180dp"
        android:padding="10dp"
        android:background="@color/colorPrimaryDark">
    
        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/header_image"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:src="@drawable/nav_icon"
            android:layout_centerInParent="true"/>
    
        <TextView
            android:id="@+id/mail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="******@mail"
            android:textColor="#fff"
            android:textSize="14sp"/>
    
        <TextView
            android:id="@+id/username"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/mail"
            android:text="***"
            android:textColor="#fff"
            android:textSize="14sp"/>
    
    
    </RelativeLayout>
    
     navigationView.setCheckedItem(R.id.nav_call);//设置默认选中的item
            navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    drawerLayout.closeDrawers();
                    return true;
                }
            });
    

    悬浮按钮和Snackbar
    布局文件

    相关文章

      网友评论

          本文标题:Android基础13

          本文链接:https://www.haomeiwen.com/subject/ofwvkxtx.html