I just migrate from api 19 Kitkat to api 21 Lollipop. And now I have found that the app icon is not there on actionbar. I feel that my app looks kind of different. So is there any way to show the app icon.
-
1Try this - [ActionBar - Display Options][1] [1]: http://stackoverflow.com/questions/26966854/app-compat-actionbar-v21-app-icon-is-not-showing/27442133#27442133 – Vintesh Dec 23 '14 at 18:20
6 Answers
In the Material theme (and AppCompat version 21 which is based on it), the Action Bar follows the material design guidelines and uses a Toolbar:
- A title and subtitle. The title should be a signpost for the Toolbar's current position in the navigation hierarchy and the content contained there. The subtitle, if present should indicate any extended information about the current content. If an app uses a logo image it should strongly consider omitting a title and subtitle.
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.
However, if you want an application icon, setLogo() is the correct method.

- 1
- 1

- 191,609
- 30
- 470
- 443
-
-
You can call it on your `getSupportActionBar()` in `onCreate()` if you'd like – ianhanniballake Dec 18 '14 at 05:36
I would also like to show my awesome app icon in Lollipop+, so here's what I used.
mActionBar.setDisplayShowHomeEnabled(true);
mActionBar.setIcon(Drawable); // Or drawable resource id.

- 8,030
- 5
- 48
- 51
This worked for me -
getSupportActionBar().setTitle("Title");
getSupportActionBar().setSubtitle("Subtitle");
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME |
ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO); // Customize if you need to
getSupportActionBar().setIcon(R.drawable.iconhere); // or setLogo
It is important that you setDisplayOptions as setIcon/setLogo doesn't seem to be working without it. Original answer - App compat actionbar v21 app icon is not showing
This code worked on my device. Let me know if you have any additional questions.

- 1
- 1

- 3,029
- 29
- 34
-
Been searching for a solution for the whole morning. This one works. Thanks! – Abdul Rahman A Samad Jan 05 '16 at 06:04
This is how I did it:
package com.your.package;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.your_icon);
}
}
Which will give you this:

- 2,063
- 1
- 20
- 23
you have to used toolbar in your app like below.
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>
v21\styles.xml
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
<item name="android:textColorPrimary">@color/textColorPrimary</item>
<item name="android:windowBackground">@color/windowBackground</item>
<item name="android:navigationBarColor">@color/navigationBarColor</item>
</style>
</resources>
in your layout use toolbar like this:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false">
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/windowBackground">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="@+id/flContent"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar">
</FrameLayout>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
in your Java file write below code for set icon:
toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.icn_menu);
//toolbar.setTitle("Title");
setTitle("Title");
//toolbar.setSubtitle("Subtitle");
//toolbar.setLogo(R.drawable.ic_launcher);
}

- 3,294
- 1
- 19
- 29
Try this:-
getSupportActionBar.setDisplayHomeAsUpEnabled(true);

- 6,677
- 1
- 14
- 26
-
-
this can help: [link](http://stackoverflow.com/questions/26525229/toolbar-navigation-icon-never-set) – Paresh P. Dec 18 '14 at 05:32