简体   繁体   中英

What padding,margin & size should I use for a MenuItem custom layout?

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.

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>
View view = mToolbar.getMenu().findItem(R.id.spinner).getActionView();

view.setPadding(0,0,0,0);

This Worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM