ActionBar logo moves left

I want to use the logo instead of homeAsUp on the actionBar to open drawerLayout, I managed to do this, but it seems that the homeAsUp space is left, so it looks like the logo has leftMargin.

This is what I did:
style.xml

<item name="android:logo">@drawable/logo_file</item> <item name="android:displayOptions">showHome|useLogo</item> 

logo_file.xml

  <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/mylogo" android:left="-10dp" </layer-list> 

activity

 getActionBar().setHomeButtonEnabled(true); getActionBar().setDisplayUseLogoEnabled(true); 

Running android:left="-10dp" does not solve the problem, it only removes 10dp to the left of the logo.

So please help me move the logo.

+4
source share
1 answer

I try to do the following in the onCreate method of activity.

 ActionBar ab = getSupportActionBar(); ab.setDisplayUseLogoEnabled(true); ab.setDisplayShowHomeEnabled(true); ab.setDisplayShowHomeEnabled(false); ab.setHomeAsUpIndicator(R.drawable.logo_actionbar); //this is your app logo or whatever youre using ab.setDisplayHomeAsUpEnabled(true); 

As long as the logo is trimmed correctly, it will be laid out as expected, without worrying about add-ons and offsets, although if you use the box there is a great example on the Android website that shows how to properly configure the drop.

+1
source

All Articles