亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

Android實現(xiàn)側滑菜單DrawerLayout

瀏覽:40日期:2022-09-24 09:40:34

本文實例為大家分享了Android實現(xiàn)側滑菜單的具體代碼,供大家參考,具體內容如下

點擊左側滑動

效果如下

Android實現(xiàn)側滑菜單DrawerLayout

代碼實現(xiàn)過程:

1.導入框架build.gradle中

//materialDesignimplementation ’com.google.android.material:material:1.0.0’

2.xml文件

主要的界面放在DrawerLayout 中,需要強調的是側滑菜單也就是下圖顯示的TextView一定要設置layout_gravity屬性,我是從左側滑動的,所以設置為start

<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:layout_height='match_parent' android: android:fitsSystemWindows='true' tools:context='.MainActivity'> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width='match_parent' android:layout_height='match_parent'> <androidx.appcompat.widget.Toolbar android: android:layout_width='match_parent' android:layout_height='?attr/actionBarSize' android:background='@color/colorPrimary' app:layout_constraintTop_toTopOf='parent' app:popupTheme='@style/ThemeOverlay.AppCompat.Light' /> </androidx.constraintlayout.widget.ConstraintLayout> <TextView android:layout_width='match_parent' android:layout_height='match_parent' android:layout_gravity='start' android:background='#FFFFFF' android:fitsSystemWindows='true' android:text='i am a textView' /></androidx.drawerlayout.widget.DrawerLayout>

3.MainActivity

綁定xml文件中的toobar

protected void setupToobar() { toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (null != getSupportActionBar()) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } }

MainActivity 中將點擊之后觸發(fā)側邊滑動的圖片ic_menu動態(tài)放到toolbr中

@Override protected void setupViews() { setupToobar(); drawerLayout = findViewById(R.id.drawer); if (null != getSupportActionBar()) { getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu); } }

android.R.id.home 觸發(fā)左側滑動

@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: drawerLayout.openDrawer(GravityCompat.START); break; case R.id.item_search: Toast.makeText(MainActivity.this, '搜索', Toast.LENGTH_SHORT).show(); } return true; }

到這就結束了。

4.后話

可以在主內容區(qū)里面再放一個布局,里面放各個fragment,就可以實現(xiàn)每個頁面都有側滑菜單的效果。側滑菜單里面的布局可以新建一個xml文件,然后include,可以看起來舒服點吧。其他的效果后面慢慢來吧。github下載地址

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: 最新国产v亚洲v欧美v专区 | 欧美性禁片在线观看 | 免费人成在线视频播放2022 | 免费看麻豆视频 | 国产高清不卡一区二区 | 成人一区专区在线观看 | 精品视频一区二区三区在线观看 | 久久青青操 | 欧美一级成人一区二区三区 | 国产xxxx做受欧美88xx00tube | 欧美国产人妖另类色视频 | 国产福利一区二区 | 欧美一区二区三区免费不卡 | 久久精品国产亚洲网站 | 亚洲综合亚洲综合网成人 | 国产精品臀控福利在线观看 | 在线观看国产一区二区三区 | 青青草国产青春综合久久 | 国产精品免费_区二区三区观看 | 成人看片黄a毛片 | 国产精品美女福利视频一区 | 久久五月婷 | 金发美女与黑人巨大交 | 亚洲精品亚洲人成在线麻豆 | 欧美视频网站免费看 | 综合色吧 | www涩| 国产成人精品视频 | 亚洲精品第一国产综合高清 | 女人牲交视频一级毛片 | 咪咪久久 | 欧美视频日韩视频 | 亚洲激情婷婷 | 欧美一级aa免费毛片 | 一级全黄毛片 | 毛片视频免费网站 | 永久免费毛片在线播放 | 国产三级日产三级 | 国产在线精品二区韩国演艺界 | 亚洲欧美日韩国产精品第不页 | 国产成人综合手机在线播放 |