简体   繁体   中英

Is it possible to add an icon of our app in ActionBar when I already have a back button in there?

The most left will be the back button (unless we're on the Main / base activity), and then I want to insert a logo of my app, then the app's title.

In my onCreate:

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

and in my onOptionItemSelected:

    case android.R.id.home:
    NavUtils.navigateUpFromSameTask(this);
    return true;

I've tried adding:

    getSupportActionBar().setIcon(R.drawable.actionbaricon);

under the code I've posted first. It works on my Main activity, where it has no back button (although the icon was placed on the middle of the action bar & erases my app title). But in activities where I have a back button, it only allows the back button (and the app title)

First: Add the new icon on your menu.xml within values. Then handle the menu on your activity on onOptionsItemSelected().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM