Action Bar: Up Icon

An “up” icon appears on the action bar (left):

enter image description here

In my Activity method, onCreate()I installed the following things:

actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);

My question is:

  • How can I implement onClickListener“tolerance” on this icon so that when the user clicks on it, the application will go to the top-level hierarchy ?

  • How can I use only the left arrow without the default icon for Android in the "tolerance" section of the action bar?

+5
source share
1 answer

To implement onClickListener instead just grab it into onOptionsItemSelected:

public boolean onOptionsItemSelected(MenuItem item)
{
    switch (item.getItemId())
    {
        case android.R.id.home:
            // Do what you want here
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

:

, android: icon . , android: , .

+3

All Articles