How to change hamburger icon in Android (NavigationDrawer)

前端 未结 3 2010
别跟我提以往
别跟我提以往 2020-12-17 00:58

Before write this thread I have try to implement the different solution that I found in stackoverflow, but nothing work properly.

I\'m developing an Android applucat

3条回答
  •  抹茶落季
    2020-12-17 01:41

    Simple and Elegant solution

    Place

    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.dashboardicon);//your icon here
    

    after

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer,toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();
    

    Overall Solution in Navigation Activity

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer,toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();
    
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.dashboardicon);
    
        navigationView= (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    

    Note: It doesnt need any setNavigationOnClickListener()

提交回复
热议问题