<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 1. 前言 `NavigationView`是`Material`庫中提供的一個控件,它不僅是嚴格按照`Material Design`的要求來設計的,而且可以將滑動菜單頁面的實現變得非常簡單。 # 2. 使用 ## 2.1 依賴 由于需要使用圓形圖片,所以這里引入一個開源庫: ``` // https://mvnrepository.com/artifact/de.hdodenhof/circleimageview implementation 'de.hdodenhof:circleimageview:3.1.0' ``` ## 2.2 實現 這里側滑菜單需要一些列表項,所以這里還是在`res`目錄下新建一個`menu`文件夾,然后我們在這下面創建`nav_item.xml`文件。 ~~~ <?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/item1" android:icon="@drawable/ic_baseline_add_24" android:title="第一個按鈕" /> <item android:id="@+id/item2" android:icon="@drawable/ic_baseline_add_24" android:title="第二個按鈕" /> </group> </menu> ~~~ 接下來應該準備`headerLayout`了,這是一個可以隨意定制的布局,這里簡單起見,就在`headerLayout`中放置頭像、用戶名、郵箱地址這3項內容吧。右擊`layout`文件夾→`New`→`Layout resource file`,創建一個`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:background="@color/teal_700" android:padding="10dp"> <!--圓角圖片組件--> <de.hdodenhof.circleimageview.CircleImageView android:layout_width="70dp" android:layout_height="70dp" android:layout_centerInParent="true" android:src="@drawable/icon"/> <TextView android:id="@+id/user_mail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="張三" android:textColor="@color/white" android:textSize="18sp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/user_mail" android:text="張三" android:textColor="@color/white" android:textSize="18sp"/> </RelativeLayout> ~~~ 準備工作做完,就可以開始主題`NavigationView`,在`Activity`的第二個控件部分方式這個控件。 ~~~ <?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" android:id="@+id/drawerlayout" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <!--使用FAB,需要使用androidx.coordinatorlayout.widget.CoordinatorLayout包裹起來--> <androidx.coordinatorlayout.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 將內容包裹起來 --> <androidx.appcompat.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="@color/teal_200"/> <!--引入下拉刷新控件--> <androidx.swiperefreshlayout.widget.SwipeRefreshLayout android:id="@+id/swiperefreshLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="?attr/actionBarSize"> <!--下拉刷新的內容--> <TextView android:layout_width="wrap_content" android:layout_height="?attr/actionBarSize" android:text="測試下拉刷新" /> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout> <!--FAB懸浮按鈕--> <com.google.android.material.floatingactionbutton.FloatingActionButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="16dp" android:src="@drawable/ic_baseline_add_24" app:elevation="8dp" /> </androidx.coordinatorlayout.widget.CoordinatorLayout> <!--側滑菜單內容--> <com.google.android.material.navigation.NavigationView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="start" app:menu="@menu/nav_item" app:headerLayout="@layout/nav_header" /> </androidx.drawerlayout.widget.DrawerLayout> ~~~ 效果: ![](https://img.kancloud.cn/bf/90/bf908eded368c8408f0b655ac417b2c8_394x613.png) 對應的`Activity`的內容: ~~~ class TestActivity : AppCompatActivity() { // 找到控件 val swiperefreshLayout by lazy { findViewById<SwipeRefreshLayout>(R.id.swiperefreshLayout) } val toolbar by lazy { findViewById<Toolbar>(R.id.toolbar) } val drawerlayout by lazy { findViewById<DrawerLayout>(R.id.drawerlayout) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_test) // 設置下拉刷新的圓圈的顏色 swiperefreshLayout.setColorSchemeResources(R.color.purple_700) // 模擬數據耗時請求 swiperefreshLayout.setOnRefreshListener { refershData() } // 設置Toolbar setSupportActionBar(toolbar) supportActionBar?.setDisplayHomeAsUpEnabled(true) toolbar.setNavigationIcon(R.drawable.ic_baseline_menu_24) toolbar.setNavigationOnClickListener { // 打開側滑 drawerlayout.openDrawer(GravityCompat.START) } } fun refershData() { // 模擬請求,耗時兩秒結束 thread { Thread.sleep(2000) runOnUiThread { // 設置停止下拉刷新 swiperefreshLayout.isRefreshing = false } } } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看