【问题标题】:change position of items on the toolbar更改工具栏上项目的位置
【发布时间】:2016-08-21 11:53:52
【问题描述】:

我想改变工具栏项目的位置,但我没有找到重力


我有 menu_main.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="haythamayyash.myapplication.MainActivity">
  <item
    android:id="@+id/action_settings"
    android:orderInCategory="2"
    android:title="@string/action_settings"
    app:showAsAction="never"/>


<item
    android:id="@+id/backbutton"
    android:orderInCategory="1"
    android:title="back"
  android:icon="@drawable/ic_action_name"
  app:showAsAction="ifRoom"


    />


   </menu> 

我有activity_main.xml

 <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout          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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="haythamayyash.myapplication.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"
    >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"

 />


</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

      </android.support.design.widget.CoordinatorLayout>

项目默认显示在工具栏的右侧, 如何从右到左更改项目的位置?

【问题讨论】:

标签: android android-toolbar


【解决方案1】:
app:showAsAction="never"

这将使选项隐藏。只有当您点击菜单图标(屏幕右上角的 3 个点)或手机的菜单按钮时才会显示。

app:showAsAction="always"

这将始终在导航栏中显示该选项。

android:orderInCategory="1"

这将决定期权的位置/顺序

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多