Home » Android » android – Logo are not displayed in Actionbar, using AppCompat

android – Logo are not displayed in Actionbar, using AppCompat

Posted by: admin April 23, 2020 Leave a comment

Questions:

I don’t know where I missed something, but I can’t set my logo in my actionbar.
My AndroidManifest.xml:

<application 
    android:icon="@drawable/application_icon" 
    android:label="@string/icon_name"
    android:logo="@drawable/actionbar_logo"
    android:theme="@style/PolarTheme">

And also I set my logo in my activity tag in the manifest:

<activity 
    android:name=".Main"
    android:theme="@style/PolarThemeLogo"
    android:logo="@drawable/actionbar_logo"
    android:windowSoftInputMode="adjustPan">
</activity>

This is in my themes.xml:

<style 
    name="PolarThemeLogo" parent="Theme.AppCompat.Light.DarkActionBar">  
    <item name="colorPrimary">@color/mainColor500</item>
    <item name="colorPrimaryDark">@color/mainColor700</item>
    <item name="colorAccent">@color/accentColorA200</item>

    <item name="actionBarStyle">@style/MyActionBarLogo</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

My styles.xml:

<style name="MyActionBarLogo" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="background">@color/mainColor500</item>
    <item name="displayOptions">useLogo</item>
</style>

In my Main.java:

public class Main extends ActionBarActivity {

@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);    
    ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle("");
    actionBar.setDisplayUseLogoEnabled(true);

Any ideas?

UPDATE – SOLVED

I removed all the android:logo attributes from my AndroidManifest.xml and I modified my MyActionBarLogo style like this:

<style name="MyActionBarLogo" parent="@style/Widget.AppCompat.Light.ActionBar">
    <item name="background">@color/mainColor500</item>
    <item name="logo">@drawable/actionbar_logo</item>
    <item name="displayOptions">useLogo|showHome</item>
</style>

Now the actionbar is displaying my logo. 🙂

How to&Answers:

I removed all the android:logo attributes from my AndroidManifest.xml and I modified my MyActionBarLogo style like this:

<style name="MyActionBarLogo" parent="@style/Widget.AppCompat.Light.ActionBar">
    <item name="background">@color/mainColor500</item>
    <item name="logo">@drawable/actionbar_logo</item>
    <item name="displayOptions">useLogo|showHome</item>
    </style>

Now the actionbar is displaying my logo. 🙂

Answer:

I use the following code to show the logo, hope it would be helpful.

getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.logo);

Answer:

just add 3 lines in Java File and do not add code in XML and Android manifest.

    getSupportActionBar().setDisplayUseLogoEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setIcon(R.mipmap.ic_launcher);