How to change margin or padding of menu items?

时间:2016-04-15 15:20:05

标签: android

Noob question. I'm using Toolbar and menu in Android app. How i can to change margin or padding between two menu items?

All answers i found is about Sharlock bar (https://stackoverflow.com/questions/15678467/how-to-add-padding-between-menu-items-in-android) or old Action bar (https://stackoverflow.com/questions/21131814/how-to-padding-between-actionbars-menu-items-icon-when-using-the-support-librare).

I think the answer near with style files, but i realy stack what parent or item name i need for my case.

My sample menu:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">

<item android:id="@+id/menu_contents"
    android:title="@string/menu_contents"
    android:icon="@drawable/ic_format_list_numbered"
    android:orderInCategory="2"
    app:showAsAction="always" />

<item android:id="@+id/menu_search"
    android:title="@string/menu_search"
    android:icon="@drawable/ic_search"
    android:orderInCategory="100"
    app:showAsAction="always" />

<item android:id="@+id/menu_settings"
    android:title="@string/menu_settings"
    android:orderInCategory="100"
    app:showAsAction="never" />

Thank you!

1 个答案:

答案 0 :(得分:1)

您需要以编程方式在MenuItem上使用ActionProvider分配setActionProvider(),这是为您要更改的项目创建的。