Action Bar's onClick listener for the Home button Action Bar's onClick listener for the Home button android android

Action Bar's onClick listener for the Home button


if anyone else need the solution

@Overridepublic boolean onOptionsItemSelected(MenuItem item) {    int id = item.getItemId();    if (id == android.R.id.home) {        onBackPressed();  return true;    }    return super.onOptionsItemSelected(item);}


I use the actionBarSherlock,after we set supportActionBar.setHomeButtonEnabled(true);
we can override the onMenuItemSelected method:

@Overridepublic boolean onMenuItemSelected(int featureId, MenuItem item) {    int itemId = item.getItemId();    switch (itemId) {    case android.R.id.home:        toggle();        // Toast.makeText(this, "home pressed", Toast.LENGTH_LONG).show();        break;    }    return true;}

I hope this work for you ~~~ good luck


if we use the system given action bar following code works fine

getActionBar().setHomeButtonEnabled(true);@Overridepublic boolean onMenuItemSelected(int featureId, MenuItem item) {    int itemId = item.getItemId();    switch (itemId) {    case android.R.id.home:      //do your action here.        break;    }    return true;}