문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top