nelzkie
nelzkie

Reputation: 233

Can someone help me create an Up Button in action bar

Im developing an application where the home view will use dashboard design. I saw in android design pattern that they introduce a new concept of using Up Button. Im confuse a little bit cause up button and back button is always the same except that you can use Up button to go directly in your home view. Can someone tell me how to create an Up Button in action bar sherlock? Please help. Thank you.

Upvotes: 2

Views: 3173

Answers (1)

RedChris
RedChris

Reputation: 523

If you have already implemented the action bar, you should be able to set up home button using the following code.

This in the onCreate

getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);

This as a separate method

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

        case android.R.id.home:
            // app icon in action bar clicked; go home
            Intent intentHome = new Intent(this, TargetActivity.class);
            intentHome.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intentHome);
            return true;

        default:
            return super.onOptionsItemSelected(item);
    }
}

This should work, if it's the same thing your trying to do.

Upvotes: 11

Related Questions