Show both logo and app name in android action bar

I have set these two lines of code to display the logo and application name in the action bar, but only the application name appears, for example in the screenshot:

enter image description here

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

      

Do I need other code to show both? I added this to the manifest, but the same result:

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

      

I am working on a tabbed activity with an action bar.

Could you help me? Thanks you

+3


source to share


4 answers


Decided to add

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

      



The use of the logo in the action bar is disabled by default in Android 5.0 Lollipop.

+12


source


Image shows where to use the code Add these 3 lines to onCreate (Bundle) of your activity class:



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

      

+4


source


Try this in your .xml style:

<!-- 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 if this creates problems with high api levels, but works for me on API 10.

+2


source


Have you run the app in an emulator or on a real device? I think the Design page in the Fragment does not show the app icon when using the L or 21 layout API. (As shown below)

no icon

But when you downgrade to API 19 or inflate the snippet it shows (as shown below)

show icon

enter image description here

0


source







All Articles