简体   繁体   中英

Navigation Drawer Activity Android Studio

In Android Studio, for the Navigation Drawer Activity, there is a three-lined symbol, which, once you click it, then the navigation drawer menu shows up from the left side of the screen. What is this three-lined symbol called?

Also, how do you get this three-lined symbol to appear on the screen??

Please help!

private ActionBarDrawerToggle toggle;
private DrawerLayout drawer;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_side_options);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

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

    drawer.addDrawerListener(toggle);
    toggle.syncState();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    //getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    //getSupportActionBar().setHomeButtonEnabled(true);
    //getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_camera);

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}

@Override
public void onBackPressed() {
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.side_options, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    if (toggle.onOptionsItemSelected(item)) {
        return true;
    }

    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    /* if (id == R.id.action_settings) {
        return true;
    } */

    return super.onOptionsItemSelected(item);
}

三线符号称为汉堡图标

private DrawerLayout mdrawerLayout;
    private ActionBarDrawerToggle mToogle;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_account);
 mdrawerLayout = (DrawerLayout) findViewById(R.id.drawer_Layout);
        mToogle = new ActionBarDrawerToggle(this, mdrawerLayout, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

        mdrawerLayout.addDrawerListener(mToogle);
        mToogle.syncState();

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    public boolean onOptionsItemSelected(MenuItem Item){

        if (mToogle.onOptionsItemSelected(Item)) {

            return true;
        }

        return super.onOptionsItemSelected(Item);

            }

add this into your java file

add this code to get that icon

ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                    this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
            drawer.setDrawerListener(toggle);
            toggle.syncState();

or you can also do as below

right click on package name>New>Activity>Naviagation Drawer Activity

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM