Reputation: 1670
I try to show icon in action bar with below codes:
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.drawable.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
but instead of show R.drawable.ic_launcher
logo, it shows back button like below image:
I used:
what should i do? tnx
Upvotes: 2
Views: 515
Reputation: 15625
setLogo()
or setIcon()
method, none of them will work if you haven't set the DisplayOptions
properly.
Just do this,
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME |
ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO);
actionBar.setIcon(R.drawable.ic_launcher);
You can customize the constants as you like.
UPDATE
Please add this to hide the back button,
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
Upvotes: 2
Reputation: 3770
The "up" affordance indicator is provided by a drawable specified in the homeAsUpIndicator attribute of the theme. To override it with your own custom version it would be something like this:
<style name="Theme.MyFancyTheme" parent="android:Theme.Holo">
<item name="android:homeAsUpIndicator">@drawable/my_fancy_up_indicator</item>
</style>
If you are supporting pre-3.0 with your application be sure you put this version of the custom theme in values-v11 or similar.
Upvotes: 0
Reputation: 518
Try this:
getSupportActionBar().setIcon(R.drawable.ic_launcher);
Instead of
getSupportActionBar().setLogo(R.drawable.ic_launcher);
Upvotes: 1