【问题标题】:Placing OverFlow Menu On Left Side of ToolBar将溢出菜单放在工具栏的左侧
【发布时间】:2016-01-03 16:06:58
【问题描述】:

我的工具栏上有一个溢出菜单,用于在我的活动之间导航。

<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=".HomePage">

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

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

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

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

带有所有这些选项的溢出按钮出现在我的工具栏的右侧。有人知道怎么把它一直放在左边吗?

这是一个相关但次要的问题。我没有任何碎片。都是活动。我想在我的工具栏上在它们之间导航。什么是最好的解决方案?同样,我创建了溢出菜单,它似乎工作正常。这通常是最好的路线吗?由于缺少片段,我正在避免使用导航抽屉。

谢谢。

【问题讨论】:

    标签: android


    【解决方案1】:

    如果您真的想在左侧有一个溢出菜单,您需要在xml 中创建自己的自定义工具栏,而不是使用您自己的版本替换现有的工具栏,如下例所示:

    这对我来说就像做梦一样:在活动中我有这个:

    //hiding default app icon
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowHomeEnabled(false);
    //displaying custom ActionBar
    View mActionBarView = getLayoutInflater().inflate(R.layout.my_action_bar, null);
    actionBar.setCustomView(mActionBarView);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM) my_action_bar.xml:
    
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/turquoise">
    
        <ImageButton 
            android:id="@+id/btn_slide"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:background="@null"
            android:scaleType="centerInside"
            android:src="@drawable/btn_slide"
            android:paddingRight="50dp"
            android:onClick="toggleMenu"
            android:paddingTop="4dp"/>
    </RelativeLayout>
    

    来自Positioning menu items to the left of the ActionBar in Honeycomb

    请注意,在 Android 应用中,左侧曾经是导航抽屉菜单。如果您想使用它而不是溢出菜单,请检查:Android Actionbar Left Menu

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多