Using Home icon as a navigation back button

I’d like to enable clicking on the home icon. This click would take user one screen back. Maybe it should take user back to front screen.  For now, act as a back button.

Nothing more simple!

1. @Override

public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_drill, menu);
// enable home icon to be a button
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
return true;

 

2.

@Override

public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {

case android.R.id.home:
onBackPressed();
return true;

}

}

Simple. Little arrow to the left is drawn next to the icon. I didn’t have to create an image.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s