Android Actionbar Left Menu

2019-06-24 01:17发布

问题:

I am working on android application. I have to add a menu on the left side of Action Bar. I am able to add menu on the right side but along with right side menu, I also want to add a menu on left side of Action Bar just like :

I have spent hours on searching how to achieve that left side menu, but no success. How can I achieve that? Thanks!

回答1:

This is called Navigation Drawer, You can look at the official android tutorial here, and this one too



回答2:

You cant align menu to left .you should use customview for your actionbar



回答3:

If you are not specifically into the navigational drawer, like a back button or anything you like, you can use

ActionBar actionbar = getSupportActionBar();
actionbar.setHomeAsUpIndicator(R.drawable.ic_arrow_back_black_24dp);

and call

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() ==android.R.id.home){
            //todo work here
            return true;
        }
        return super.onOptionsItemSelected(item);
    }