Question

I have a problem with native actionbar (not ABS). In normal state icon has 26 px margins on both side.

enter image description here

But when I call setDisplayHomeAsUpEnabled(true) it decreases this margins and in result it looks much narrower.

enter image description here

Do you have any idea how to maintain this margins when setDisplayHomeAsUpEnabled(true) is called? (prefferably without workarounds and custom views)

Thanks is advance.

Was it helpful?

Solution

You can set the margin of the home-icon like that: (just call the below code inside your Activity's onCreate(...) method)

ImageView ivIcon = (ImageView) findViewById(android.R.id.home);

FrameLayout.LayoutParams lpIcon = (FrameLayout.LayoutParams) ivIcon.getLayoutParams();

lpIcon.topMargin = lpIcon.bottomMargin = yourmargin;
lpIcon.leftMargin = lpIcon.rightMargin = yourmargin;
ivIcon.setLayoutParams(lpIcon);

Its kind of a hack but I used it to get rid of the margin completely by setting it to 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top