具有溢出菜单自定义动作条布局自定义、布局、菜单、动作

2023-09-12 02:32:12 作者:我一口盐汽水喷死你

我用的是 actionbarsherklock 库的自定义操作栏是这样的:

I use the actionbarsherklock library with custom action bar look like this:

我的自定义实现:

  ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

    // Do any other config to the action bar
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // set custom view
    View actionBarView = getLayoutInflater().inflate(
            R.layout.action_bar_default, null);

    View btnMenuLeft= actionBarView.findViewById(R.id.btnMenuLeft);
    btnMenuLeft.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            toggle();
        }
    });

    View btnMenuShare= actionBarView.findViewById(R.id.btnMenuShare);
    ActionBar.LayoutParams params = new ActionBar.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    actionBar.setCustomView(actionBarView, params);

    // Hide the home icon
    actionBar.setIcon(android.R.color.transparent);
    actionBar.setLogo(android.R.color.transparent);

这里是自定义布局:

And here is the custom layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/nav_bar_bg"
android:gravity="center"
android:orientation="horizontal" >

<!-- menu button -->
    <ImageButton
        android:id="@+id/btnMenuLeft"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/list_btn"
        android:clickable="false"
        android:duplicateParentState="true"
        android:focusable="false" />

    <!-- logo -->
    <ImageView       
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:src="@drawable/app_logo" />

    <!-- share button -->
    <ImageButton
         android:id="@+id/btnMenuShare"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/action_btn"
        android:clickable="false"
        android:duplicateParentState="true"
        android:focusable="false" />

现在的问题是,我想添加一个过流菜单来分享这样的一个按钮:

The problem is that I want add an over flow menu to share button like this one:

请告诉我,我怎么能做到这一点的自定义操作栏布局。

Please tell me how can I do that with the custom action bar layout.

推荐答案

似乎没有右键办法来解决这个问题,所以我尝试了黑客通过使用弹出窗口与列表适配器假动作栏溢出菜单。 它看起来像这样的例子:http://rajeshandroiddeveloper.blogspot.com/2013/07/android-popupwindow-example-in-listview.html

Seem there is no right way to solve this problem, so I tried a hack by using popup windows with list adapter to fake action bar overflow menu. It look like this example: http://rajeshandroiddeveloper.blogspot.com/2013/07/android-popupwindow-example-in-listview.html