国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

更多QQ空间微信QQ好友腾讯朋友复制链接
您的位置:首頁/技術文章
文章詳情頁

Android studio有關側滑的實現代碼

【字号: 作者:豬豬瀏覽:32日期:2022-09-23 18:02:10

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

附圖片:

Android studio有關側滑的實現代碼

//主頁面的布局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.cgvv.com.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() { //實現左右滑動 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: //跳轉到退出頁面 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有關側滑的實現代碼

總結

到此這篇關于Android studio有關側滑的實現的文章就介紹到這了,更多相關Android studio有關側滑的實現內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Android
相關文章:
主站蜘蛛池模板: 欧美另类videosbestsex视频 | 免费看的一级片 | 九九99久麻豆精品视传媒 | 免费播放欧美毛片 | 亚洲国产经典 | 成人欧美视频在线观看 | 亚洲天堂伊人 | 欧美三级三级三级爽爽爽 | 免费看a级毛片 | 欧美一区精品 | 在线免费观看国产视频 | 成年女人免费看 | 国产免费久久精品99久久 | 亚洲爱视频 | 黄色美女一级片 | 一级毛片免费播放 | 国产欧美另类性视频 | 亚洲国产影视 | 久久久久久久久毛片精品 | 亚洲人成网址在线播放a | 女子张开腿让男人桶视频 | 国产精品视频男人的天堂 | 中文无线乱码二三四区 | 玖草视频在线 | 99精品视频在线在线视频观看 | 美国全免费特一级毛片 | 91福利国产在线观一区二区 | 亚洲美女性生活视频 | 一本久道在线 | 欧美日韩在线观看一区 | 日韩免费一级毛片欧美一级日韩片 | 日本在线资源 | 亚洲在线观看网站 | 欧美另类精品一区二区三区 | 欧美在线日韩在线 | 男女同床爽爽视频免费 | 一级毛片在线播放 | 好爽~好硬~好紧~蜜芽 | 一级毛片免费在线播放 | 成人午夜性a一级毛片美女 成人午夜亚洲影视在线观看 | 久草在线视频在线观看 |