How to center&left&right align the ActionBar icons in Android

泄露秘密 提交于 2019-12-01 14:45:12

问题


hi there I want align a set of icons in toolbar like below picture.

I googled and after some change I have:

mainActivity.xml

...

<include
    android:id="@+id/tool_bar_bottom"
    layout="@layout/tool_bar"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    />
 ....

And in menu_bottom.xml:

<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/action_forward"

        android:title="forward"
        android:orderInCategory="100"
        android:icon="@drawable/ic_action_arrow_forward"
        android:layout_alignParentRight="true"
        app:showAsAction="always"
        ></item>


    <item
        android:id="@+id/action_zoom_in"
        android:orderInCategory="200"
        android:title="zoom in"
        android:icon="@drawable/ic_action_zoom_in"
        app:showAsAction="always"
        ></item>



    <item
        android:id="@+id/action_home"
        android:orderInCategory="300"
        android:title="home"
        android:icon="@drawable/ic_action_home"
        app:showAsAction="always"
        ></item>


    <item
        android:id="@+id/action_refresh"
        android:orderInCategory="400"
        android:title="refresh"
        android:icon="@drawable/ic_action_refresh"
        app:showAsAction="always"
        ></item>

    <item
        android:id="@+id/action_zoom_out"
        android:orderInCategory="500"
        android:title="zoom out"
        android:icon="@drawable/ic_action_zoom_out"
        app:showAsAction="always"
        ></item>

    <item
        android:id="@+id/action_back"
        android:orderInCategory="600"
        android:title="back"
        android:icon="@drawable/ic_action_arrow_back"
        android:layout_alignParentLeft="true"
        app:showAsAction="always"
        ></item>


</menu>

I added android:layout_alignParentLeft/right="true" for left and right also

According the picture,I wand float right icon to left and right icon to right.

Also I want float center all other icon beside each other...

The code do not any change.

Also I add android:layout_centerVertical = "true" to all other icons...

how can correct display view?

来源:https://stackoverflow.com/questions/31132007/how-to-centerleftright-align-the-actionbar-icons-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!