Add custom layout to ActionBar with Gravity Left?

2019-06-13 17:23发布

问题:

The ActionBar shows a space on the left side of the custom view. I want to set my custom view align left of Actionbar.

I'm trying to set

    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayShowHomeEnabled(false);

and any other method like setLogo(null),But it's not work.

My code is like

    ABCMainView actionLayout = new ABCMainView(this); //my custom view
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setCustomView(actionLayout);

My ActionBar is android-appcompat-v21.

How can i do this?

回答1:

Try with this in your Toolbar xml config

android:contentInsetStart="0dp"

Base on Chris Banes' response https://stackoverflow.com/a/26495926/1568429