How to add padding/margin between icon and Up-Butt

2019-06-27 23:35发布

I have to set margin of 10dp between up button and icon, 5 dp between icon and Title in default action bar (android 4.2.2), can anyone please suggest how it can be done.

I don't want to create custom action bar as my required is exactly same as default action bar with change in height, and padding between icon, up button and title. Also change in text size.

Can this be achieved using defualt action bar. I am able to change the height of action bar.

1条回答
孤傲高冷的网名
2楼-- · 2019-06-27 23:45

You can add a padding / margin by getting the ImageView of the icon from the ActionBar.

This is how:

ImageView icon = (ImageView) findViewById(android.R.id.home);
FrameLayout.LayoutParams iconLp = (FrameLayout.LayoutParams) icon.getLayoutParams();
iconLp.topMargin = iconLp.bottomMargin = 0;
icon.setLayoutParams(iconLp);

Edit: Use this code for example in your Activity's onCreate method.

查看更多
登录 后发表回答