Skip to content

Use BMB in Action Bar

Weiping Huang edited this page Mar 28, 2017 · 3 revisions

How to put BMB in action bar?

Use BMB in Action Bar

BMB is easy to use in action bar to act as a menu button. Check the demo for more details.

  1. Create a Custom Action Bar. Firstly, we need a xml file for our custom-action-bar:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@android:color/transparent">

    <com.nightonke.boommenu.BoomMenuButton
        android:id="@+id/action_bar_left_bmb"
        android:layout_width="56dp"
        android:layout_height="56dp"
        app:bmb_backgroundEffect="false"/>

    <TextView
        android:id="@+id/title_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:textAllCaps="true"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#fff"
        android:layout_toRightOf="@+id/action_bar_left_bmb"
        android:layout_toEndOf="@+id/action_bar_left_bmb"
        />

    <com.nightonke.boommenu.BoomMenuButton
        android:id="@+id/action_bar_right_bmb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        app:bmb_backgroundEffect="false"
        app:bmb_boomEnum="boomParabola_2"/>

</RelativeLayout>

Notice that in action bar, we must remove the background of bmb. To do that, use app:bmb_backgroundEffect="false" or bmb.setBackgroundEffect(false); in java file.

  1. Use Custom-Action-Bar in Activity.

In onCreate method in activity:

ActionBar mActionBar = getSupportActionBar();
assert mActionBar != null;
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);

View actionBar = mInflater.inflate(R.layout.custom_actionbar, null);
TextView mTitleTextView = (TextView) actionBar.findViewById(R.id.title_text);
mTitleTextView.setText(R.string.app_name);
mActionBar.setCustomView(actionBar);
mActionBar.setDisplayShowCustomEnabled(true);
((Toolbar) actionBar.getParent()).setContentInsetsAbsolute(0,0);

BoomMenuButton leftBmb = (BoomMenuButton) actionBar.findViewById(R.id.action_bar_left_bmb);
BoomMenuButton rightBmb = (BoomMenuButton) actionBar.findViewById(R.id.action_bar_right_bmb);
  1. Finally Customize BMBs.

Customize bmbs as we do it before:

leftBmb.setButtonEnum(ButtonEnum.TextOutsideCircle);
leftBmb.setPiecePlaceEnum(PiecePlaceEnum.DOT_9_1);
leftBmb.setButtonPlaceEnum(ButtonPlaceEnum.SC_9_1);
for (int i = 0; i < leftBmb.getPiecePlaceEnum().pieceNumber(); i++)
    leftBmb.addBuilder(BuilderManager.getTextOutsideCircleButtonBuilder());

rightBmb.setButtonEnum(ButtonEnum.Ham);
rightBmb.setPiecePlaceEnum(PiecePlaceEnum.HAM_4);
rightBmb.setButtonPlaceEnum(ButtonPlaceEnum.HAM_4);
for (int i = 0; i < rightBmb.getPiecePlaceEnum().pieceNumber(); i++)
    rightBmb.addBuilder(BuilderManager.getHamButtonBuilder());

Now your bmb in action bar is ready for a boom.