The application icon does not show on action bar

jeep picture jeep · Nov 10, 2014 · Viewed 52.3k times · Source

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.

Answer

Gabriele Mariotti picture Gabriele Mariotti · Nov 10, 2014

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);