【问题标题】:Positioning menu items to the left of the ActionBar in Honeycomb在 Honeycomb 中将菜单项定位到 ActionBar 的左侧
【发布时间】:2011-03-15 00:39:17
【问题描述】:

我想在 Honycomb 的 ActionBar 左侧放置一些菜单项,但没有找到说明如何执行此操作的文档。看起来应该是可能的,因为联系人应用程序在导航栏的左侧有搜索。关于如何将菜单项设置到左侧的任何想法?

【问题讨论】:

    标签: android android-3.0-honeycomb android-actionbar


    【解决方案1】:

    ActionBar 支持应用程序图标和常规 ActionBar 图标之间的自定义布局。示例:

    // Set the custom section of the ActionBar with Browse and Search.
    ActionBar actionBar = getActionBar();
    mActionBarView = getLayoutInflater().inflate(R.layout.action_bar_custom, null);
    actionBar.setCustomView(mActionBarView);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    

    【讨论】:

    • 如何判断自定义视图是否在ActionBar中被点击?
    • @CACuzcatlan,使用 actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
    • 我使用了它,但布局仍然没有全宽,因为我提到了 match_parent 自定义视图父...任何建议。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-20
      • 2019-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多