zkminusck
zkminusck

Reputation: 1240

Logo are not displayed in Actionbar, using AppCompat

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. :)

Upvotes: 31

Views: 28298

Answers (3)

saigopi.me
saigopi.me

Reputation: 14908

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

Upvotes: 1

alijandro
alijandro

Reputation: 12147

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

Upvotes: 27

zkminusck
zkminusck

Reputation: 1240

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. :)

Upvotes: 25

Related Questions