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

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

Android studio有關側(cè)滑的實現(xiàn)代碼

瀏覽:20日期:2022-09-23 18:02:10

最近寫課設,因為是新手,實現(xiàn)起來比較麻煩。所以寫下此筆記,免得我以后忘記了。

附圖片:

Android studio有關側(cè)滑的實現(xiàn)代碼

//主頁面的布局activity_main.xml:

<?xml version='1.0' encoding='utf-8'?><android.support.v4.widget.DrawerLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:tools='http://schemas.android.com/tools' xmlns:qpp='http://schemas.android.com/apk/res-auto' android: android:layout_width='match_parent' android:layout_height='match_parent' android:fitsSystemWindows='true' tools:openDrawer='start'> <TextView android:layout_width='wrap_content' android:layout_height='wrap_content' android:text='Hello World!' /> <android.support.design.widget.NavigationView android: android:layout_width='207dp' android:layout_height='match_parent' android:layout_gravity='left' android:fitsSystemWindows='true' qpp:headerLayout='@layout/stumenu1' qpp:menu='@menu/stumenu1' /></android.support.v4.widget.DrawerLayout>

頭部的布局(放入layout)stumenu1.xml:

<?xml version='1.0' encoding='utf-8'?><!--學生左滑后界面--><android.support.constraint.ConstraintLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent'> <LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' android:orientation='vertical' android:layout_width='match_parent' android:layout_height='match_parent' android:gravity='center' > <ImageView android: android:layout_width='72dp' android:layout_height='72dp' android:layout_marginTop='75dp' android:src='http://www.aoyou183.cn/bcjs/@drawable/student' /> <TextView android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:textSize='20sp' android:layout_marginTop='20dp' android:textColor='#282525' android:text='測試APP'/> </LinearLayout></android.support.constraint.ConstraintLayout>

菜單的布局:(放在menu文件夾)stumenu1

<?xml version='1.0' encoding='utf-8'?><menu xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto'> <group android:checkableBehavior='single'> <item android: android:icon='@drawable/ic_launcher_background' android:checkable='true' android:title=' 測試結果'/> <item android: android:icon='@drawable/ic_launcher_background' android:title=' 錯題'/> <item android: android:icon='@drawable/ic_launcher_background' android:title=' 得分'/> <item android: android:icon='@drawable/ic_launcher_background' android:title=' 退出'/> </group></menu>

MainActivity.java:

package com.example.cholewu.slide;import android.content.Intent;import android.support.annotation.NonNull;import android.support.design.widget.NavigationView;import android.support.v4.widget.DrawerLayout;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.MenuItem;import android.widget.Toast;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //左滑菜單 initView(); } private void initView() { //實現(xiàn)左右滑動 final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); //菜單控件 final NavigationView nv = findViewById(R.id.nav_view); nv.setItemIconTintList(null);nv.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) {switch (item.getItemId()){ case R.id.exit: //跳轉(zhuǎn)到退出頁面 Toast.makeText(MainActivity.this,'你已退出登錄!',Toast.LENGTH_SHORT).show(); Intent intent=new Intent(); intent.setClass(MainActivity.this,Exit.class); startActivity(intent); item.setChecked(true); break;}item.setCheckable(true);//設置可選項item.setChecked(true);//設置被選中drawer.closeDrawers();//關閉菜單欄return true; } }); }}

(注意:如果直接復制代碼的話,android.support.design.widget.NavigationView可能會出錯,需要自己在design那里布局,如果出錯,可以看看以下NavigationView右邊是否有下載圖案,點擊下載就行了)

Android studio有關側(cè)滑的實現(xiàn)代碼

總結

到此這篇關于Android studio有關側(cè)滑的實現(xiàn)的文章就介紹到這了,更多相關Android studio有關側(cè)滑的實現(xiàn)內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網(wǎng)!

標簽: Android
相關文章:
主站蜘蛛池模板: 一级韩国aa毛片免费观看 | 国产精品视频第一页 | 亚洲黄色在线网站 | 色综合久久天天综合绕观看 | 国产国语在线播放视频 | 乱爱性全过程免费视频 | 国产精品视频久久久久 | 嫩模被xxxx视频在线观看 | 国产大陆亚洲精品国产 | 91久久国产视频 | 一级特色黄大片 | 欧美日韩国产一区 | 交在线观看网站视频 | 青青久在线视频免费观看 | 免费高清小黄站在线观看 | 国产免费高清无需播放器 | 久久午夜网| 日本无翼乌邪恶大全彩h邪恶师 | 国产限制路线1线路2线路3 | 亚洲精品午夜久久aaa级久久久 | 综合视频网 | 精品国精品自拍自在线 | 美美女高清毛片视频黄的一免费 | 妞干网免费观看视频 | 国产一区二区视频在线观看 | 中文字幕亚洲精品 | 未满十八18周岁禁止免费国产 | 久久www成人看片 | 天天狠天天透天干天天怕处 | 欧美人成毛片在线播放 | heyzo北条麻妃在线播放 | 国产亚洲欧美视频 | 亚洲综合激情另类图片专区 | 精品国产一区二区三区不卡 | 无码精品日韩中文字幕 | 亚洲大成色www永久网址 | 国产肥老妇免费视频 | 爱啪网站| 日韩欧美一二三 | 国产色片在线观看 | 亚洲邪恶天堂影院在线观看 |