Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Back Button in Material Design

I cannot find a tutorial about adding this button in the Action bar in Material Design.

example image

How can I add this into the action bar on Lollipop?

like image 475
masterphp Avatar asked Apr 20 '15 19:04

masterphp


2 Answers

try this

in on create:

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

in your activity class (assuming you want to close this activity)

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}
like image 188
Tomer Shemesh Avatar answered Oct 02 '22 04:10

Tomer Shemesh


Material Design Tutorial This will give you brief idea how to implement material app.

If you are using ActionBarActivity with AppCompat Theme use:

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Also you may have to call setHomeButtonEnabled(true) in same manner. It will look like this:

enter image description here

like image 24
Harry's Lab Avatar answered Oct 02 '22 03:10

Harry's Lab