第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用選項卡和片段處理導航項

使用選項卡和片段處理導航項

牛魔王的故事 2021-05-10 15:26:38
我創(chuàng)建了一個導航抽屜并添加了這樣的布局activity_main <?xml version="1.0" encoding="utf-8"?><android.support.v4.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:id="@+id/drawer_layout"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:fitsSystemWindows="true"    tools:openDrawer="start">    <include        layout="@layout/app_bar_main"        android:layout_width="match_parent"        android:layout_height="match_parent" />    <android.support.design.widget.NavigationView        android:id="@+id/nav_view"        android:layout_width="wrap_content"        android:layout_height="match_parent"        android:layout_gravity="start"        android:fitsSystemWindows="true"        app:headerLayout="@layout/nav_header_main"        app:menu="@menu/activity_main_drawer" /></android.support.v4.widget.DrawerLayout>我得到如下所示的結(jié)果: 上面的代碼將FirstSemester()和SecondSemester()片段綁定到所有導航項。這可能不是正確的解決方法,因此,我需要建議和幫助,謝謝。
查看完整描述

3 回答

?
浮云間

TA貢獻1829條經(jīng)驗 獲得超4個贊

其次,如何將AppBar標題更改為選定的Navigation項目的標題?


在MainActivity類的onNavigationItemSelected()方法中,您可以執(zhí)行以下操作:


@SuppressWarnings("StatementWithEmptyBody")

@Override

public boolean onNavigationItemSelected(MenuItem item) {

    // Handle navigation view item clicks here.

    int id = item.getItemId();


    if (id == R.id.year1) {

        getSupportActionBar().setTitle("Year 1");

        setupViewPager(viewPager);

    } else if (id == R.id.year2) {

        getSupportActionBar().setTitle("Year 2");

        setupViewPager2(viewPager);

    } else if (id == R.id.year3) {

        getSupportActionBar().setTitle("Year 3");

        setupViewPager3(viewPager);

    } else if (id == R.id.year4) {

        getSupportActionBar().setTitle("Year 4");

        setupViewPager4(viewPager);

    } else if (id == R.id.year5) {

        getSupportActionBar().setTitle("Year 5");

        setupViewPager5(viewPager);

    } else if (id == R.id.nav_share) {


    } else if (id == R.id.nav_send) {


    }


    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    drawer.closeDrawer(GravityCompat.START);

    return true;

}

關(guān)于第一個問題,您正在為導航抽屜中單擊的任何項目顯示一個viewpager(第一和第二個學期),因此您不應期望外觀正常。粗略的方法,但是效率不是太差。


查看完整回答
反對 回復 2021-05-26
  • 3 回答
  • 0 關(guān)注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號