Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android sherlock setDisplayHomeAsUpEnabled not working and how to set custom target?

Tags:

java

android

I've called setDisplayHomeAsUpEnabled(true) and the arrow is showing, but it goes no where, I'd also like to manually set the link/target of the button to go to a custom location.

How can I specify a custom location? Thankyou.

Thanks

like image 363
williamsandonz Avatar asked Feb 18 '13 02:02

williamsandonz


1 Answers

If you are using ActionBarSherlock like the title says, you should instead use:

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Either way, to handle the click, you have to make a case for android.R.id.home in onOptionsItemSelected()

Eg:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        //do your own thing here
        return true;
    default: return super.onOptionsItemSelected(item);  
    }
}

Also, by custom location, I don't know what you mean, you can certainly make a new Intent() to do something.

However, to keep things consistent with the Android guidelines, you should be using the Up icon to actually go up.

like image 143
A--C Avatar answered Oct 20 '22 12:10

A--C