Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action bar: about up affordance icon

In action bar, there is an icon called "up affordance" showed below (the left-most one):

enter image description here

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

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

My Question is:

  1. how can I implement an onClickListener on this "up affordance" icon, so that when user click on it, the application will be navigated to the upper level hierarchy ?

  2. how can I have only the left arrow without the android default icon of "up affordance" part on action bar?

like image 462
Mellon Avatar asked Feb 14 '12 16:02

Mellon


1 Answers

For implementing an onClickListener, instead just catch it in 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);
    }
}

For question two, this page states:

Using a logo instead of icon

By default, the system uses your application icon in the action bar, as specified by the android:icon attribute in the or element. However, if you also specify the android:logo attribute, then the action bar uses the logo image instead of the icon.

like image 107
Joakim Berglund Avatar answered Oct 15 '22 03:10

Joakim Berglund