最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Drawer menu in android studio not "solid" - Stack Overflow

programmeradmin1浏览0评论

So for a school project we need to create an app with eco-house, and I got a problem its when I open the first time the drawer everything fine because header is "solid" and nothing goes through it but when I change fragment all of them (fragments) goes trough the header of the menu like in the pictures :
Drawer Menu in header Calendar in header

This is my MainActivity.java :

    DrawerLayout drawerDL;
        ActionBarDrawerToggle toggle;
    FragmentManager fm;
    NavigationView navNV;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);

        // Barre de navigation
        drawerDL = findViewById(R.id.drawer);
        navNV = findViewById(R.id.nav_view);

        // Header de la barre de navigation
        View headerView = navNV.getHeaderView(0);
        TextView mail_name = headerView.findViewById(R.id.user_name);

        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();

        assert bundle != null;
        String email = bundle.getString("mail");
        mail_name.setText(email);

        toggle = new ActionBarDrawerToggle(this, drawerDL,
                        R.string.open, R.string.close);

        fm = getSupportFragmentManager();

        drawerDL.setDrawerListener(toggle);
        toggle.syncState();
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);


        navNV.setNavigationItemSelectedListener(this);
        navNV.getMenu().performIdentifierAction(R.id.habitat, 0);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        return toggle.onOptionsItemSelected(item);
    }
    @Override
    public boolean onNavigationItemSelected(MenuItem item){
        if (item.getItemId() == R.id.monhabitat){
            fm.beginTransaction().replace(R.id.contentFL,
                    new MonHabitatFragment())mit();
        } else if (item.getItemId() == R.id.habitat) {
            fm.beginTransaction().replace(R.id.contentFL,
                    new HabitatsFragment())mit();
        }
        else if (item.getItemId() == R.id.requete) {
            fm.beginTransaction().replace(R.id.contentFL,
                    new MesRequetesFragment())mit();
        }
        else if (item.getItemId() == R.id.setting) {
            fm.beginTransaction().replace(R.id.contentFL,
                    new ParametresFragment())mit();
        }
        else if (item.getItemId() == R.id.disconnect) {
            fm.beginTransaction().replace(R.id.contentFL,
                    new SeDeconnecterFragment())mit();
        }
        drawerDL.closeDrawer(GravityCompat.START);
        return true;
    }


}

And my xml :

    xmlns:app=";
    android:id="@+id/drawer"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <FrameLayout
        android:id="@+id/contentFL"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="95"/>


    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"

        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:layout_marginTop="?android:attr/actionBarSize"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/nav_menu"/>


</androidx.drawerlayout.widget.DrawerLayout>

if needed I can send other part of my code ! Ty for your help

发布评论

评论列表(0)

  1. 暂无评论