slash89mf
slash89mf

Reputation: 1067

Show both logo and app name in action bar android

i have set these two lines of code to display both logo and app name in action bar, but only app name appears, like in the screenshot:

enter image description here

actionBar.setDisplayUseLogoEnabled(true);
actionBar.setLogo(R.drawable.icon);

Do i need other code to show both? I have added this in manifest but same result:

<application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:logo="@drawable/icon"

I'm working on a Tabbed activity with action bar.

Can you help me? Thank you

Upvotes: 12

Views: 31833

Answers (4)

Shubhdeep Singh
Shubhdeep Singh

Reputation: 407

Image Shows where to use the codeAdd these 3 lines in the onCreate(Bundle) method of your Activity class:

    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setLogo(R.mipmap.ic_launcher4);
    getSupportActionBar().setDisplayUseLogoEnabled(true);

Upvotes: 8

Jason Saruulo
Jason Saruulo

Reputation: 1897

Try this one in your style.xml:

<!-- ActionBar styles -->
<style name="MyActionBar"
    parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">

    <item name="android:icon">@drawable/logo</item>
    <item name="logo">@drawable/logo</item>
    <item name="displayOptions">useLogo|showHome|showTitle</item>
</style>

Don't know whether this makes problems with high api levels but worked for me on API 10.

Upvotes: 4

slash89mf
slash89mf

Reputation: 1067

Solved adding

    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setLogo(R.drawable.icona);
    getSupportActionBar().setDisplayUseLogoEnabled(true);

Using logo in actionbar is disabled by default in Android 5.0 Lollipop.

Upvotes: 30

bjiang
bjiang

Reputation: 6078

Did you run you app in emulator or real device? I think on the Design page in the fragment does not show the icon of the app when using the layout of API L or 21.(as show below)

no icon

But when you change to API 19 or inflate the fragment into tap, it shows.(as show below)

show icon

enter image description here

Upvotes: 0

Related Questions