1

I have upgraded an older Android app to androidx.

Now there is a big space before the icon in the Actionbar.

enter image description here

I was looking into it and found a question where it explains that it is due to

app:contentInsetStartWithNavigation

and

app:contentInsetStart

Is there a way to set them both to 0dp programmatically?

My code at the moment:

public static void initializeActionBar(Context context, ActionBar bar, boolean showBackButton){
    if (bar != null) {
        bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
        bar.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.wood2));
        bar.setIcon(R.drawable.icon_white); //custom logo
        if(showBackButton){
            bar.setDisplayHomeAsUpEnabled(true);
        }
    }
}

This code is used in various activities like this:

ActivityTools.initializeActionBar(this,getSupportActionBar(), false);
Cœur
  • 37,241
  • 25
  • 195
  • 267
Marshall
  • 1,353
  • 3
  • 17
  • 38

1 Answers1

2

You need to use Toolbar for this

First, use a Toolbar

then you can use setContentInsetStartWithNavigation(int insetStartWithNavigation)

SAMPLE CODE

class DemoActivity : AppCompatActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_recurring_billing)

        setSupportActionBar(mToolbar)

        mToolbar!!.setContentInsetsAbsolute(10, 0)
        mToolbar!!.contentInsetStartWithNavigation =10



    }
}
AskNilesh
  • 67,701
  • 16
  • 123
  • 163