欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2020年06月04日 09:53:15   作者:努力學(xué)習(xí)中.....  
這篇文章主要介紹了Android studio有關(guān)側(cè)滑的實(shí)現(xiàn)代碼,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

最近寫課設(shè),因?yàn)槭切率?,?shí)現(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:id="@+id/drawer_layout"
  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:id="@+id/nav_view"
    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"?>
<!--學(xué)生左滑后界面-->
<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:id="@+id/person"
      android:layout_width="72dp"
      android:layout_height="72dp"
      android:layout_marginTop="75dp"
      android:src="@drawable/student"
      />
    <TextView
      android:id="@+id/stutv"
      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:id="@+id/result"
      android:icon="@drawable/ic_launcher_background"
      android:checkable="true"
      android:title=" 測試結(jié)果"/>

  <item
    android:id="@+id/w1"
    android:icon="@drawable/ic_launcher_background"

    android:title=" 錯題"/>
  <item
    android:id="@+id/s1"
    android:icon="@drawable/ic_launcher_background"
    android:title=" 得分"/>

  <item
    android:id="@+id/exit"
    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() {

    //實(shí)現(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);//設(shè)置可選項
        item.setChecked(true);//設(shè)置被選中
        drawer.closeDrawers();//關(guān)閉菜單欄
        return true;
      }

    });
  }
}

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

在這里插入圖片描述

總結(jié)

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

相關(guān)文章

  • Android layoutAnimation詳解及應(yīng)用

    Android layoutAnimation詳解及應(yīng)用

    這篇文章主要介紹了Android layoutAnimation詳解及應(yīng)用的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • Android編程實(shí)現(xiàn)狀態(tài)保存的方法分析

    Android編程實(shí)現(xiàn)狀態(tài)保存的方法分析

    這篇文章主要介紹了Android編程實(shí)現(xiàn)狀態(tài)保存的方法,結(jié)合實(shí)例形式分析了Android狀態(tài)保存的原理、實(shí)現(xiàn)方法與相關(guān)注意事項,需要的朋友可以參考下
    2017-08-08
  • android控件Spinner(下拉列表)的使用例子

    android控件Spinner(下拉列表)的使用例子

    這篇文章主要給大家介紹了關(guān)于android控件Spinner(下拉列表)的使用例子,在Android開發(fā)中下拉框(Spinner)是常用的UI控件之一,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-11-11
  • Android自定義垂直拖動seekbar進(jìn)度條

    Android自定義垂直拖動seekbar進(jìn)度條

    這篇文章主要為大家詳細(xì)介紹了Android自定義垂直拖動seekbar進(jìn)度條,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • Android實(shí)現(xiàn)水波紋效果實(shí)例代碼

    Android實(shí)現(xiàn)水波紋效果實(shí)例代碼

    大家好,本篇文章主要講的是Android實(shí)現(xiàn)水波紋效果實(shí)例代碼,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下
    2022-02-02
  • 詳解android與服務(wù)端交互的兩種方式

    詳解android與服務(wù)端交互的兩種方式

    這篇文章主要介紹了詳解android與服務(wù)端交互的兩種方式,此處介紹兩種方式:使用Google原生的Gson解析json數(shù)據(jù),使用JSONObject解析json數(shù)據(jù),有興趣的可以了解一下
    2017-07-07
  • Android登錄界面的實(shí)現(xiàn)代碼分享

    Android登錄界面的實(shí)現(xiàn)代碼分享

    好久沒有搞android項目了,手都有點(diǎn)松了,今天因?yàn)轫椖康男枰?,繼續(xù)弄android知識,在項目中登錄界面是項目中比較常見的最基本的功能,對android登錄界面的實(shí)現(xiàn)感興趣的朋友一起學(xué)習(xí)吧
    2016-11-11
  • Android SharedPreferences存取操作以及封裝詳解

    Android SharedPreferences存取操作以及封裝詳解

    SharedPreferences是安卓平臺上一個輕量級的存儲類,用來保存應(yīng)用的一些常用配置,比如Activity狀態(tài),Activity暫停時,將此activity的狀態(tài)保存到SharedPereferences中;當(dāng)Activity重載,系統(tǒng)回調(diào)方法onSaveInstanceState時,再從SharedPreferences中將值取出
    2021-11-11
  • Android發(fā)送短信方法總結(jié)

    Android發(fā)送短信方法總結(jié)

    這篇文章主要介紹了Android發(fā)送短信方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android發(fā)送短信的原理與具體實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-11-11
  • Android編程實(shí)現(xiàn)類似于圓形ProgressBar的進(jìn)度條效果

    Android編程實(shí)現(xiàn)類似于圓形ProgressBar的進(jìn)度條效果

    這篇文章主要介紹了Android編程實(shí)現(xiàn)類似于圓形ProgressBar的進(jìn)度條效果,結(jié)合實(shí)例形式分析了Android通過自定義View實(shí)現(xiàn)圓形進(jìn)度條效果的操作方法,需要的朋友可以參考下
    2017-03-03

最新評論