I am currently using a custom layout for my MenuItem:
The code is basic:
<?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 pixel is described in the Android Design and Guidelines, I have no idea at the margin, padding, width and height I should use for this icon, so it will look legit on all devices.
My current layout:
<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 totally wrong and is not similar at all to other MenuItems.
Note: Margins are used to add spaces between an image and the description of that image. CSS Padding is used if we want to create a space between an element and the edge of the container or the border. It is also useful in the requirement of changing the size of the element.
In HTML margins work the same way in giving space away from the edge of the page. Borders simply wrap the element. A border can wrap immediately around an element, or it may look further away from an element if more padding has been applied to the element. Padding provides space around the element.
margin: 0; padding: 0; } What this code does is to run over, like an elephant, every default style on the page. This can be useful as sometimes different browsers have different default stylings for different elements.
android:minWidth
should be 56dip
, android:paddingBottom
and android:paddingTop
should be 8dip
. Found in <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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With