What padding, margin and size should be used for custom MenuItem layout?

I am currently using my own layout for my MenuItem:

enter image description here

Main code:

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/menu_custom" android:actionLayout="@layout/menu_layout" android:showAsAction="always"/> </menu> 

While the icon size in a pixel is described in Android Design and Guidelines, I have no idea about the margins, fill, width, and height that I should use for this icon, so it will look legal on all devices.

My current layout is:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/searchProgressWrapper" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageButton android:id="@+id/ivfolder" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="center" android:scaleType="fitCenter" android:background="@drawable/abs__item_background_holo_dark" android:src="@drawable/ic_menu_archive" /> </RelativeLayout> 

The big problem is that, as you can see, the width of the icon is completely incorrect and not at all like other MenuItems.

+6
source share
2 answers

android:minWidth should be 56dip , android:paddingBottom and android:paddingTop should be 8dip . Found at <sdk>/platforms/android-17/data/res/values/dimens.xml :

 <!-- Minimum width for an action button in the menu area of an action bar --> <dimen name="action_button_min_width">56dip</dimen> <!-- Vertical padding around action bar icons. --> <dimen name="action_bar_icon_vertical_padding">8dip</dimen> 
+14
source
 View view = mToolbar.getMenu().findItem(R.id.spinner).getActionView(); view.setPadding(0,0,0,0); 

This worked for me.

0
source

All Articles