当我同时添加“抽屉导航”和“底部导航”但单击“导航”时不显示片段吗?

当我单击底部导航图标时,片段不会仅显示可见的抽屉导航和底部导航。我被困在这个问题几天。请指导我为解决此问题而进行的更改

  

抽屉活动xml

<androidx.coordinatorlayout.widget.CoordinatorLayout
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"
tools:context=".activities.Draweractivity">

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/Apptheme.AppBarOverlay">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popuptheme="@style/Apptheme.PopupOverlay">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/app_name"
            android:layout_gravity="center"
            android:textColor="@color/colorTitle"
            android:textSize="20sp"
            android:textStyle="bold"
            android:id="@+id/toolbar_title" />

    </androidx.appcompat.widget.Toolbar>

//将文件的home活​​动包含在抽屉活动中

  

活动主xml

<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
tools:context=".activities.Homeactivity">

<LinearLayout
    android:id="@+id/content_area"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

</LinearLayout>

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    app:itemIconTint="@color/bottom_nav_item"
    app:itemTextColor="@color/bottom_nav_item"
    android:background="@color/colorPrimary"
    app:menu="@menu/nav_menu"
    tools:ignore="MissingConstraints" />

  

家庭活动Java

public class Homeactivity extends AppCompatactivity implements BottomNavigationView.OnNavigationItemSelectedListener {

BottomNavigationView bottomNavigationView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);


    bottomNavigationView = findViewById(R.id.bottom_navigation);
    bottomNavigationView.setOnNavigationItemSelectedListener(this);

    displayFragment(new HomeFragment());

}


private void displayFragment(Fragment fragment ) {
    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.content_area,fragment)
            .commit();
}

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    Fragment fragment;
    switch (item.getItemId()) {
        case R.id.nav_home:
            fragment = new HomeFragment();
            break;
        case R.id.nav_fav:
            fragment = new FavouritesFragment();
            break;
        case R.id.nav_set:
            fragment = new SettingsFragment();
            break;
        default:
            fragment = new HomeFragment();
            break;
    }
    displayFragment(fragment);
    return true;
 }
}
  

抽屉活动Java

public class Draweractivity extends AppCompatactivity {

Toolbar mToolbar;

private RecyclerView recyclerView;
private SwipeRefreshLayout recyclerLayout;
Drawer resultDrawer;
accountHeader headerResult;
ArrayList<Object> filesList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTheme( Constant.theme);
    setContentView(R.layout.drawer_activity);


    //Toolbar
    mToolbar = (Toolbar) findViewById( R.id.toolbar);
    mToolbar.setBackgroundColor( Constant.color);
    setSupportactionBar(mToolbar);
    getSupportactionBar().setDisplayShowTitleEnabled(false);

}
  

主要活动Java

public class Mainactivity extends AppCompatactivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate( savedInstanceState );


    Intent intent = new Intent( Mainactivity.this,Homeactivity.class );
    startactivity( intent );
    finish();

   }
}
peggyxin 回答:当我同时添加“抽屉导航”和“底部导航”但单击“导航”时不显示片段吗?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3005655.html

大家都在问