The application icon does not show on action bar

53,636

Solution 1

You are using the AppCompat version 21+ and it is normal.

The Action Bar follows the material design guidelines and uses a Toolbar. As you can read here:

The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.

If you would like an application icon (but I discourage it), you can use the method setLogo().

Something like this:

ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.drawable.my_logo);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);

Solution 2

This issue comes when you use support library revised 21.

Use:

ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.drawable.ic_launcher);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);

It worked for me or you can use toolbar. A Toolbar is a generalization of action bars for use within application layouts.

In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.

Reference: https://developer.android.com/reference/android/support/v7/widget/Toolbar.html

Solution 3

Make sure you have the icon set in the manifest.xml file, in the application tag as:

    android:icon="@drawable/launcher_icon"

Then in the onCreate method insert the following lines:

    ActionBar ab =getSupportActionBar(); 
    ab.setDisplayShowHomeEnabled(true);
    ab.setIcon(R.drawable.launcher_icon);

Solution 4

This is a common "problem".Before you pull your hairs out make sure you are using:

import android.support.v7.app.ActionBar; //or the v4, haven't tried with that though

and not:

import android.app.ActionBar;

and then:

ActionBar actionBar;
actionBar = getSupportActionBar();

instead of:

actionBar = getActionBar();

And finally:

if (actionBar != null) {
        // enabling action bar app icon and behaving it as toggle button           
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setIcon(R.drawable.your_icon);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
    }

Solution 5

Attribute logo is only used in API level 11 and higher (current min is 8), I was also confused about this question, maybe google just don't want the icon to show on material design, when the minimum sdk is set to 14 or higher and under 21,it uses holo theme, it has an icon, but appcompat style is more like material design I think, maybe google just forget to modify the holo theme

Share:
53,636
jeep
Author by

jeep

Updated on July 09, 2022

Comments

  • jeep
    jeep almost 2 years

    I followed up the instructions of building a new android project and I got a runnable one except a problem with action bar. The problem is that the application icon is not showed beside the application title on action bar. I created the project with the configuration below:

    • Minimum required SDK:API 8: Android 2.2(Froyo)

    • Target SDK:API 21:Android 4.X(L preview)

    • Compile With:API 21:Android 4.X(L preview)

    • Theme:Holo Light with Dark Action Bar(Eclipse set the corresponding appcompat theme)

    • Android Support Library 21.0.1

    • Android SDK Build-tools 21.1.1

    Because my minimum sdk is api 8 which does not support action bar, so the project includes a appcompat_v7 library to allow the action bar feature. If I set the minimum sdk to api 14(android 4.0) or higher, then the project does not include appcompat_v7 library and application icon is showed successfully also. But I need my app to support older android os as low as api 8. So what should I do to fix this problem? Really appreciate you guys attention.

    P.S: I went through the task above on windows ,mac, eclipse , android studio and got the same result.