最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android DrawerLayout側(cè)邊導(dǎo)航欄的實現(xiàn)步驟

 更新時間:2025年10月28日 09:54:56   作者:某空m  
DrawerLayout是Android開發(fā)中一種常見的布局組件,常用于實現(xiàn)側(cè)滑菜單效果,它允許一個或多個子視圖在用戶交互時從屏幕邊緣滑出,下面通過本文給大家介紹Android DrawerLayout側(cè)邊導(dǎo)航欄的實現(xiàn)步驟,感興趣的朋友跟隨小編一起看看吧

簡介

DrawerLayout是Android開發(fā)中一種常見的布局組件,常用于實現(xiàn)側(cè)滑菜單效果,它允許一個或多個子視圖在用戶交互時從屏幕邊緣滑出。

實現(xiàn)步驟

1.完成布局文件,以DrawerLayout為根布局,其第一個子布局為主布局,第二個子布局為側(cè)邊導(dǎo)航欄的布局。

DrawerLayout最多只能有兩個直接子View

注意:
側(cè)邊導(dǎo)航欄的布局必須設(shè)置屬性android:layout_gravity,側(cè)邊欄才不會顯示,否則側(cè)邊導(dǎo)航欄會默認直接顯示在頁面。

android:layout_gravity="start" //側(cè)邊導(dǎo)航欄從左邊出現(xiàn)
android:layout_gravity="end" //側(cè)邊導(dǎo)航欄從右邊出現(xiàn)
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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:layout_width="match_parent"
    android:id="@+id/main"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:fitsSystemWindows="true"
    tools:context=".all.view.MainActivity">
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/mainpage_viewpager2"
        android:fitsSystemWindows="true"
        android:layout_marginTop="30dp"
        android:layout_width="match_parent"
        android:layout_height="0dp">
        <androidx.viewpager2.widget.ViewPager2
            android:background="@android:color/transparent"
            android:fitsSystemWindows="true"
            android:id="@+id/main_viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
        />
    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:elevation="1dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:menu="@menu/main_nav_bottom_menu"
        android:background="@drawable/bottom_nav_view"
        app:labelVisibilityMode="labeled"
        app:itemBackground="@drawable/bottom_nav_view"
        app:itemTextColor="@color/main_item_text_selector"
        app:itemActiveIndicatorStyle="@null"
        style="@style/CustomBottomNavigationView"
         app:itemRippleColor="@color/white"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        >
    </com.google.android.material.bottomnavigation.BottomNavigationView>
    <ImageView
        android:id="@+id/bottom_navigation_add"
        android:layout_width="48dp"
        android:layout_height="60dp"
        android:src="@drawable/add"
        android:elevation="200dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>
    </androidx.constraintlayout.widget.ConstraintLayout>
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="310dp"
        android:layout_height="match_parent"
        android:background="#F5F5F5"
        android:layout_gravity="start"
        >
        <ScrollView
        android:id="@+id/drawerlayout_scroolview"
        android:layout_width="match_parent"
        android:layout_height="650dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginTop="65dp"
        >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/white"
                app:cardCornerRadius="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                app:cardElevation="0dp"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="55dp"
                    android:orientation="horizontal"
                    >
                    <ImageView
                        android:layout_gravity="center_vertical"
                        android:src="@drawable/addfirends"
                        android:layout_marginLeft="15dp"
                        android:layout_width="28dp"
                        android:layout_height="28dp"/>
                    <TextView
                        android:layout_gravity="center_vertical"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:text="添加好友"
                        android:textSize="14dp"/>
                </LinearLayout>
            </androidx.cardview.widget.CardView>
            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/white"
                app:cardCornerRadius="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                app:cardElevation="0dp"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="55dp"
                    android:orientation="horizontal"
                    >
                    <ImageView
                        android:layout_gravity="center_vertical"
                        android:src="@drawable/creators_center"
                        android:layout_marginLeft="15dp"
                        android:layout_width="28dp"
                        android:layout_height="28dp"/>
                    <TextView
                        android:layout_gravity="center_vertical"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:text="創(chuàng)作者中心"
                        android:textSize="14dp"/>
                </LinearLayout>
            </androidx.cardview.widget.CardView>
            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/white"
                app:cardCornerRadius="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                app:cardElevation="0dp"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="55dp"
                        android:orientation="horizontal"
                        >
                        <ImageView
                            android:layout_gravity="center_vertical"
                            android:src="@drawable/my_draft"
                            android:layout_marginLeft="15dp"
                            android:layout_width="25dp"
                            android:layout_height="25dp"/>
                        <TextView
                            android:layout_gravity="center_vertical"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:text="我的草稿"
                            android:textSize="14dp"/>
                    </LinearLayout>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="55dp"
                        android:orientation="horizontal"
                        >
                        <ImageView
                            android:layout_gravity="center_vertical"
                            android:src="@drawable/my_comment"
                            android:layout_marginLeft="15dp"
                            android:layout_width="28dp"
                            android:layout_height="28dp"/>
                        <TextView
                            android:layout_gravity="center_vertical"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:text="我的評論"
                            android:textSize="14dp"/>
                    </LinearLayout>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="55dp"
                        android:orientation="horizontal"
                        >
                        <ImageView
                            android:layout_gravity="center_vertical"
                            android:src="@drawable/browse_records"
                            android:layout_marginLeft="15dp"
                            android:layout_width="28dp"
                            android:layout_height="28dp"/>
                        <TextView
                            android:layout_gravity="center_vertical"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:text="瀏覽記錄"
                            android:textSize="14dp"/>
                    </LinearLayout>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="55dp"
                        android:orientation="horizontal"
                        >
                        <ImageView
                            android:layout_gravity="center_vertical"
                            android:src="@drawable/my_download"
                            android:layout_marginLeft="21dp"
                            android:layout_width="20dp"
                            android:layout_height="20dp"/>
                        <TextView
                            android:layout_gravity="center_vertical"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:text="我的下載"
                            android:textSize="14dp"/>
                    </LinearLayout>
                </LinearLayout>
            </androidx.cardview.widget.CardView>
            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/white"
                app:cardCornerRadius="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                app:cardElevation="0dp"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="55dp"
                        android:orientation="horizontal"
                        >
                        <ImageView
                            android:layout_gravity="center_vertical"
                            android:src="@drawable/orders"
                            android:layout_marginLeft="15dp"
                            android:layout_width="25dp"
                            android:layout_height="25dp"/>
                        <TextView
                            android:layout_gravity="center_vertical"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:text="訂單"
                            android:textSize="14dp"/>
                    </LinearLayout>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="55dp"
                        android:orientation="horizontal"
                        >
                        <ImageView
                            android:layout_gravity="center_vertical"
                            android:src="@drawable/shopping_cart"
                            android:layout_marginLeft="15dp"
                            android:layout_width="28dp"
                            android:layout_height="28dp"/>
                        <TextView
                            android:layout_gravity="center_vertical"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:text="購物車"
                            android:textSize="14dp"/>
                    </LinearLayout>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="55dp"
                        android:orientation="horizontal"
                        >
                        <ImageView
                            android:layout_gravity="center_vertical"
                            android:src="@drawable/wallet"
                            android:layout_marginLeft="15dp"
                            android:layout_width="28dp"
                            android:layout_height="28dp"/>
                        <TextView
                            android:layout_gravity="center_vertical"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:text="錢包"
                            android:textSize="14dp"/>
                    </LinearLayout>
                </LinearLayout>
            </androidx.cardview.widget.CardView>
            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/white"
                app:cardCornerRadius="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                app:cardElevation="0dp"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="55dp"
                    android:orientation="horizontal"
                    >
                    <ImageView
                        android:layout_gravity="center_vertical"
                        android:src="@drawable/small_routine"
                        android:layout_marginLeft="15dp"
                        android:layout_width="28dp"
                        android:layout_height="28dp"/>
                    <TextView
                        android:layout_gravity="center_vertical"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:text="小程序"
                        android:textSize="14dp"/>
                </LinearLayout>
            </androidx.cardview.widget.CardView>
            <androidx.cardview.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/white"
                app:cardCornerRadius="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                app:cardElevation="0dp"
                >
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="55dp"
                    android:orientation="horizontal"
                    >
                    <ImageView
                        android:layout_gravity="center_vertical"
                        android:src="@drawable/community_pact"
                        android:layout_marginLeft="15dp"
                        android:layout_width="28dp"
                        android:layout_height="28dp"/>
                    <TextView
                        android:layout_gravity="center_vertical"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:text="社區(qū)公約"
                        android:textSize="14dp"/>
                </LinearLayout>
            </androidx.cardview.widget.CardView>
        </LinearLayout>
         </ScrollView>
        <LinearLayout
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/drawerlayout_scroolview"
            android:layout_marginTop="30dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <LinearLayout
                android:layout_marginLeft="30dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <FrameLayout
                    android:layout_gravity="center_horizontal"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:background="@drawable/drawerlayout_background">
                    <ImageView
                        android:layout_marginTop="10dp"
                        android:layout_marginLeft="10dp"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:src="@drawable/sweep"/>
                </FrameLayout>
                <TextView
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="5dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="掃一掃"
                    android:textSize="12dp"/>
            </LinearLayout>
            <LinearLayout
                android:layout_marginLeft="50dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <FrameLayout
                    android:layout_gravity="center_horizontal"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:background="@drawable/drawerlayout_background">
                    <ImageView
                        android:layout_marginTop="10dp"
                        android:layout_marginLeft="10dp"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:src="@drawable/customer_service"/>
                </FrameLayout>
                <TextView
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="5dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="幫助與客服"
                    android:textSize="12dp"/>
            </LinearLayout>
            <LinearLayout
                android:layout_marginLeft="50dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <FrameLayout
                    android:layout_gravity="center_horizontal"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:background="@drawable/drawerlayout_background">
                    <ImageView
                        android:layout_marginTop="10dp"
                        android:layout_marginLeft="10dp"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:src="@drawable/set"/>
                </FrameLayout>
                <TextView
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="5dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="設(shè)置"
                    android:textSize="12dp"/>
            </LinearLayout>
        </LinearLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.drawerlayout.widget.DrawerLayout>

2.代碼控制

首先獲取DrawerLayout對象

 drawerLayout=findViewById(R.id.main);

關(guān)閉側(cè)邊導(dǎo)航欄

 drawerLayout.closeDrawers();   

打開側(cè)邊導(dǎo)航欄

 drawerLayout.openDrawer(left); 
 //上面的left既可以是菜單欄的布局對象,也可以是菜單欄的布局id

監(jiān)聽側(cè)邊導(dǎo)航欄

  drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View view, float v) {
            }
            @Override
            public void onDrawerOpened(View view) {
                Toast.makeText(MyActivity.this, "打開了側(cè)邊欄" , Toast.LENGTH_LONG).show();
            }
            @Override
            public void onDrawerClosed(View view) {
                Toast.makeText(MyActivity.this, "關(guān)閉了側(cè)邊欄" , Toast.LENGTH_LONG).show();
            }
            @Override
            public void onDrawerStateChanged(int i) {
            }
        });

NavigationView

NavigationView 是 Android 支持庫中提供的一個專門用于配合 DrawerLayout 實現(xiàn)側(cè)邊導(dǎo)航菜單的控件。它本質(zhì)上是一個可滾動的菜單容器,通常放在 DrawerLayout 的“抽屜”部分,用于顯示應(yīng)用的導(dǎo)航條目。

主要作用:

  • 顯示菜單項:通過menu屬性引用XML文件(menu.xml),自動生成可點擊的的導(dǎo)航項;
  • 添加頭部視圖:通過app:headerLayout屬性添加用戶頭像、昵稱、背景等內(nèi)容;
  • 支持狀態(tài)高亮、點擊事件:點擊某個菜單項自動高亮,可配合NavigationItemSelectedListener頁面跳轉(zhuǎn)。

1.實現(xiàn)布局文件

   <com.google.android.material.navigation.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id = "@+id/nav_view"
        android:layout_gravity="start"
        app:headerLayout="@layout/nax_drawer_header"
        app:menu = "@menu/nav_drawer_menu">
    </com.google.android.material.navigation.NavigationView>
app:menu:引用一個菜單 XML 文件,定義導(dǎo)航項
app:headerLayout:引用一個布局 XML 文件,作為導(dǎo)航頭部
android:layout_gravity="start":指定抽屜從哪邊滑出,通常是 start 表示左側(cè),end代表右側(cè);
itemIconTint, itemTextColor:設(shè)置菜單圖標(biāo)和文字的顏色

2.定義菜單

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
     <item
          android:id="@+id/it_title"
          android:title="更改頭像"
         />
    <item
        android:id="@+id/it_name"
        android:title="修改昵稱"
        />
    <item
        android:id="@+id/it_chatperson"
        android:title="在線人數(shù)"
        />
    <item
        android:id="@+id/it_gotochat"
        android:title="去聊天"
        />
    <item
        android:id="@+id/it_exit"
        android:title="退出"
        />
</menu>

3.導(dǎo)航頭部

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:orientation="vertical">
    <ImageView
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:src = "@drawable/title1"
        android:layout_marginTop="100dp"
        android:layout_gravity="center"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id = "@+id/tv_title"
        android:layout_marginTop="20dp"
        android:layout_gravity="center"
        android:text="個人中心"/>
</LinearLayout>

4.設(shè)置菜單項點擊事件

通過設(shè)置菜單項的點擊事件監(jiān)聽器setNavigationItemSelectedListener()

  navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                int id = menuItem.getItemId();
                if(id == R.id.it_chatperson){
                    Toast.makeText(MainActivity.this,"chatperson",Toast.LENGTH_SHORT).show();
                }
                else if(id == R.id.it_exit){
                    Toast.makeText(MainActivity.this,"exit",Toast.LENGTH_SHORT).show();
                }
                else if(id == R.id.it_gotochat){
                    Toast.makeText(MainActivity.this,"gotochat",Toast.LENGTH_SHORT).show();
                }
                else if(id == R.id.it_name){
                    Toast.makeText(MainActivity.this,"name",Toast.LENGTH_SHORT).show();
                }
                else if(id == R.id.it_title){
                    Toast.makeText(MainActivity.this,"title",Toast.LENGTH_SHORT).show();
                }
                return true;
            }
        });

DrawerLayout的功能和特點

1. 側(cè)滑菜單功能:DrawerLayout 提供側(cè)邊滑出菜單的實現(xiàn),允許用戶通過滑動屏幕邊緣或點擊按鈕打開抽屜菜單,提升界面簡潔性和可用性;

2. 支持左右兩側(cè)菜單:支持從屏幕的左側(cè)或右側(cè)分別展示抽屜菜單。通過 layout_gravity="start"(左側(cè))和 layout_gravity="end"(右側(cè))來指定;

3. 與 Toolbar 集成:可以與 Toolbar 和 ActionBarDrawerToggle 配合使用,在 Toolbar 上顯示圖標(biāo),通過點擊圖標(biāo)打開或關(guān)閉抽屜;

4. 內(nèi)建動畫效果:DrawerLayout 自動提供抽屜打開和關(guān)閉的動畫效果。主內(nèi)容視圖可以根據(jù)抽屜的滑動進行遮擋或平移,增強用戶體驗;

5. 支持監(jiān)聽抽屜事件:提供 DrawerListener,可以監(jiān)聽抽屜的打開、關(guān)閉、滑動、狀態(tài)變化等事件,方便開發(fā)者根據(jù)抽屜狀態(tài)執(zhí)行相關(guān)操作。

6. 適配不同屏幕大?。篋rawerLayout 可以自動適配小屏和大屏設(shè)備,適用于手機和平板等不同尺寸的屏幕,支持響應(yīng)式布局。

7. 結(jié)合 NavigationView 使用:常與 NavigationView 配合使用,后者提供了方便的菜單項管理、頭部布局和選中狀態(tài)功能,適合構(gòu)建標(biāo)準(zhǔn)的側(cè)邊導(dǎo)航菜單。

我們來講講代碼,在代碼中通過講解它的屬性,布局等來學(xué)習(xí):

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="match_parent"
    >
        <androidx.appcompat.widget.Toolbar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id = "@+id/toolbar"
            app:subtitle="子標(biāo)題"
            app:title="標(biāo)題"
            app:navigationIcon="@drawable/title"
            >
        </androidx.appcompat.widget.Toolbar>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            android:layout_gravity="center"
            android:layout_marginTop="300dp"/>
    </LinearLayout>
    <com.google.android.material.navigation.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id = "@+id/nav_view"
        android:layout_gravity="start"
        app:headerLayout="@layout/nax_drawer_header"
        app:menu = "@menu/nav_drawer_menu">
    </com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>

到此這篇關(guān)于Android DrawerLayout實現(xiàn)側(cè)邊導(dǎo)航欄的詳細步驟的文章就介紹到這了,更多相關(guān)Android DrawerLayout側(cè)邊導(dǎo)航欄內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Android開發(fā)退出程序的方法匯總

    Android開發(fā)退出程序的方法匯總

    Android程序有很多Activity,比如說主窗口A,調(diào)用了子窗口B,子窗口B又調(diào)用子窗口C,back返回子窗口B后,在B中如何關(guān)閉整個Android應(yīng)用程序呢? 下面腳本之家小編就給大家介紹android開發(fā)退出程序的幾種方法,感興趣的朋友參考下吧
    2016-03-03
  • Android編程之退出整個應(yīng)用程序的方法

    Android編程之退出整個應(yīng)用程序的方法

    這篇文章主要介紹了Android編程之退出整個應(yīng)用程序的方法,實例分析了Android直接關(guān)閉所有的Acitivity并退出應(yīng)用程序的實現(xiàn)技巧,需要的朋友可以參考下
    2015-12-12
  • 25個實用酷炫的Android開源UI框架

    25個實用酷炫的Android開源UI框架

    本文為大家分享了25個實用酷炫的Android開源UI框架,靈活運用這些UI框架可在日常工作中節(jié)省不少時間
    2018-04-04
  • android表格效果之ListView隔行變色實現(xiàn)代碼

    android表格效果之ListView隔行變色實現(xiàn)代碼

    首先繼承SimpleAdapter再使用重載的Adapter來達到效果,其實主要是需要重載SimpleAdapter,感興趣的朋友可以研究下,希望本文可以幫助到你
    2013-02-02
  • Android手機通過藍牙連接佳博打印機的實例代碼

    Android手機通過藍牙連接佳博打印機的實例代碼

    這篇文章主要介紹了Android手機通過藍牙連接佳博打印機的實例代碼,非常不錯具有參考借鑒價值,需要的朋友可以參考下
    2016-11-11
  • kotlin實現(xiàn)快遞與號碼歸屬地查詢案例詳解

    kotlin實現(xiàn)快遞與號碼歸屬地查詢案例詳解

    時間軸時一個很炫酷的效果,一般作用在物流信息上,我們同樣也可以作為一個學(xué)習(xí)對象去學(xué)習(xí)他的使用方法,同時呢,我們可以在線查詢我們的電話號碼歸屬地,巧用鍵盤的邏輯提升我們用戶體驗
    2023-02-02
  • android百度地圖之公交線路詳情搜索

    android百度地圖之公交線路詳情搜索

    本篇文章介紹了android百度地圖之公交線路詳情搜索,實現(xiàn)了百度搜索公交詳情具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2016-10-10
  • Android變形(Transform)之Camera使用介紹

    Android變形(Transform)之Camera使用介紹

    Camera主要實現(xiàn)3D的變形,有轉(zhuǎn)動,旋轉(zhuǎn)等,Camera的源碼是由Native(本地代碼)實現(xiàn),提供的接口也比較簡單,感興趣的朋友可以參考下,或許對你學(xué)習(xí)有所幫助
    2013-02-02
  • Android基于OpenCV實現(xiàn)QR二維碼檢測

    Android基于OpenCV實現(xiàn)QR二維碼檢測

    QR碼比普通一維條碼具有快速讀取和更大的存儲資料容量,也無需要像一維條碼般在掃描時需要直線對準(zhǔn)掃描儀。因此其應(yīng)用范圍已經(jīng)擴展到包括產(chǎn)品跟蹤,物品識別,文檔管理,庫存營銷等方面。本文講解Android基于OpenCV實現(xiàn)QR二維碼檢測的步驟
    2021-06-06
  • Flutter文本Text和輸入框TextField組件使用示例

    Flutter文本Text和輸入框TextField組件使用示例

    這篇文章主要為大家介紹了Flutter文本Text和輸入文本框TextField組件使用示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-08-08

最新評論

洱源县| 新疆| 五寨县| 礼泉县| 北京市| 鄢陵县| 济宁市| 宁德市| 清流县| 利津县| 峨边| 哈尔滨市| 蕉岭县| 达尔| 朔州市| 浠水县| 北海市| 志丹县| 马公市| 泊头市| 南川市| 普宁市| 台山市| 宁阳县| 郸城县| 界首市| 南通市| 时尚| 子长县| 新宁县| 大田县| 白银市| 德庆县| 岳普湖县| 红河县| 乐安县| 天水市| 长子县| 射洪县| 南京市| 宜君县|