2

I am trying to add an icon to my ActionBar for the whole Appliction.

I reference the CustomActionBarTheme in my Appication Tag in the manifest.

My ActionBars are turning Blue but there is no Icon.

Anybody have any ideas why?

Thanks

[Duplicate] show icon in actionbar/toolbar with AppCompat-v7 21

<application
        android:name=".NfcScannerApplication"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/CustomActionBarTheme"
        android:debuggable = "true" >

.

    <?xml version="1.0" encoding="UTF-8"?>

<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@style/Theme.AppCompat.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>

        <!-- Support library compatibility -->
        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
           parent="@style/Widget.AppCompat.Light.ActionBar">
        <item name="android:background">@color/cf_blue</item>
        <item name="android:icon">@drawable/ic_launcher</item>

        <!-- Support library compatibility -->
        <item name="background">@color/cf_blue</item>
        <item name="icon">@drawable/ic_launcher</item>
    </style>
</resources>
Community
  • 1
  • 1
turtleboy
  • 8,210
  • 27
  • 100
  • 199
  • http://stackoverflow.com/questions/26440279/show-icon-in-actionbar-toolbar-with-appcompat-v7-21 http://stackoverflow.com/questions/26966854/app-compat-actionbar-v21-app-icon-is-not-showing etc. – CommonsWare Mar 09 '15 at 11:34
  • @CommonsWare Thanks again Mark, worked a treat. create an answer if you like. – turtleboy Mar 09 '15 at 11:47
  • 1
    I suggest you pick whichever one of those that you like and mark this question as a duplicate. – CommonsWare Mar 09 '15 at 11:54
  • @CommonsWare When custom action bar is used, then it compulsory use both tags one for current version and another for support library. like @style/MyActionBar and @style/MyActionBar. – Arun Kumar Mar 09 '15 at 15:17
  • Does this answer your question? [how to set app icon in action bar in android](https://stackoverflow.com/questions/40908011/how-to-set-app-icon-in-action-bar-in-android) – Rajnish Sharma Jul 19 '20 at 16:35
  • Does this answer your question? [show icon in actionbar/toolbar with AppCompat-v7 21](https://stackoverflow.com/questions/26440279/show-icon-in-actionbar-toolbar-with-appcompat-v7-21) – Ryan M Jul 20 '20 at 09:15

2 Answers2

0
Objects.requireNonNull(getSupportActionBar()).setDisplayShowHomeEnabled(true);
    getSupportActionBar().setIcon(R.mipmap.ic_launcher_round);
Martin Olariaga
  • 379
  • 4
  • 4
-1
ActionBar ab=getActionBar();
ab.setIcon(R.drawable.ic_launcher)
Andy
  • 49,085
  • 60
  • 166
  • 233
Rahul M Mohan
  • 293
  • 1
  • 3
  • 12