将菜单项的位置更改为左侧

时间:2018-11-07 10:18:36

标签: java android xml android-actionbar android-toolbar

我有一个如下图所示的工具栏 enter image description here

,我想将其更改为此 enter image description here

或这个 enter image description here

下面的代码是我的菜单

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
    android:id="@+id/action_search"
    android:icon="@drawable/ic_search"
    android:orderInCategory="100"
    android:title="@string/search_title"
    app:showAsAction="always" />

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

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

1 个答案:

答案 0 :(得分:0)

设置为NavigationIcon:

Drawable drawable = ContextCompat.getDrawable(context, R.drawable.your_drawable)
toolbar.setNavigationIcon(drawable);
setSupportActionBar(toolbar);

Taken from another answer