Custom actionbar layout with overflow menu

R4j

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

enter image description here

My custom implement:

  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:

enter image description here

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

R4j

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Custom ActionBar Overflow Menu

From Dev

ActionBar with custom layout with custom menu item

From Dev

Overflow menu is not showing in Actionbar

From Dev

Android ActionBar overflow menu style

From Dev

AppCompat overflow menu overlapping actionbar

From Dev

Adding overflow menu in actionbar android

From Dev

Custom Menu item in Overflow menu

From Dev

ActionBar items appear always in Overflow Menu

From Dev

Actionbar is showing menu icons as overflow and not individual icons

From Dev

Android overflow menu positioned above actionbar/toolbar?

From Dev

Actionbar's overflow menu open/close listener

From Dev

Action buttons move to overflow menu (ActionBar)

From Dev

Actionbar items always appear in overflow menu

From Dev

Why is my overflow dropdown menu on top of the actionbar?

From Dev

Detect click on Actionbar's Overflow menu button

From Dev

Items getting added to "overflow menu" instead of the ActionBar

From Dev

How to style android actionbar overflow menu

From Dev

ActionBar overflow menu with three dots is not showing

From Dev

Actionbar's overflow menu open/close listener

From Dev

How to style android actionbar overflow menu

From Dev

actionbar overflow menu items icons padding

From Dev

custom actionbar layout using appcompat

From Dev

Android ActionBar custom layout styling

From Dev

Android ActionBar custom layout styling

From Dev

custom actionbar layout using appcompat

From Dev

The menu item isn't showing in the ActionBar, only in overflow menu

From Dev

Why my options menu changes to ActionBar overflow menu unexpectedly?

From Dev

Custom layout for sliding menu

From Dev

UWP custom control with overflow layout

Related Related

HotTag

Archive