Skip to content

Instantly share code, notes, and snippets.

@DasserBasyouni
Created July 29, 2018 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DasserBasyouni/7636536f01fa987331d3da5c8050d960 to your computer and use it in GitHub Desktop.
Save DasserBasyouni/7636536f01fa987331d3da5c8050d960 to your computer and use it in GitHub Desktop.
Custom Button Background with BoomMenu Library
package com.example...;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.nightonke.boommenu.BoomButtons.ButtonPlaceEnum;
import com.nightonke.boommenu.BoomMenuButton;
import com.nightonke.boommenu.ButtonEnum;
import com.nightonke.boommenu.OnBoomListenerAdapter;
import com.nightonke.boommenu.Piece.PiecePlaceEnum;
import com.tech.futureteric.introui.R;
public class CustomButton extends FrameLayout {
private String mButtonText, mButtonEnum, mButtonPlaceEnum, mButtonPiecePlaceEnum;
private int mButtonTextColor, mButtonBackground;
private float mButtonTextSize;
private TextView mButtonTextView;
private FrameLayout mButtonFrameLayout;
private BoomMenuButton mBoomMenuButton;
public CustomButton(Context context) {
super(context);
init(context, null);
}
public CustomButton(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public CustomButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
LayoutInflater.from(context).inflate(R.layout.view_custom_button, this, true);
final TypedArray typedArray = getContext().obtainStyledAttributes(
attrs, R.styleable.CustomButton, 0, 0);
mButtonBackground = typedArray.getResourceId(R.styleable.CustomButton_buttonBackground, -1);
mButtonText = typedArray.getString(R.styleable.CustomButton_buttonText);
if (typedArray.hasValue(R.styleable.CustomButton_buttonTextSize))
mButtonTextSize = typedArray.getDimension(R.styleable.CustomButton_buttonTextSize, 18);
if (typedArray.hasValue(R.styleable.CustomButton_buttonTextColor))
mButtonTextColor = typedArray.getColor(R.styleable.CustomButton_buttonTextColor, Color.WHITE);
mButtonEnum = typedArray.getString(R.styleable.CustomButton_buttonEnum);
mButtonPlaceEnum = typedArray.getString(R.styleable.CustomButton_buttonPlaceEnum);
mButtonPiecePlaceEnum = typedArray.getString(R.styleable.CustomButton_piecePlaceEnum);
typedArray.recycle();
mButtonTextView = findViewById(R.id.textView);
mButtonFrameLayout = findViewById(R.id.frameLayout);
mBoomMenuButton = findViewById(R.id.boomMenuButton);
invalidateAttributes();
}
private void invalidateAttributes() {
mButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonTextSize);
mButtonTextView.setTextColor(mButtonTextColor);
mButtonTextView.setText(mButtonText);
mButtonFrameLayout.setBackgroundResource(mButtonBackground);
// TODO add styles you need instead of those
if (mButtonEnum.equals("textInsideCircle"))
mBoomMenuButton.setButtonEnum(ButtonEnum.TextInsideCircle);
if (mButtonPlaceEnum.equals("buttonPlace_sc_6_4"))
mBoomMenuButton.setButtonPlaceEnum(ButtonPlaceEnum.SC_6_4);
if (mButtonPiecePlaceEnum.equals("piecePlace_dot_6_4"))
mBoomMenuButton.setPiecePlaceEnum(PiecePlaceEnum.DOT_6_4);
mButtonFrameLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mBoomMenuButton.setOnBoomListener(new OnBoomListenerAdapter() {
@Override
public void onBoomDidHide() {
mBoomMenuButton.setVisibility(INVISIBLE);
mButtonTextView.setVisibility(VISIBLE);
}
@Override
public void onBoomWillShow() {
mBoomMenuButton.setVisibility(VISIBLE);
mButtonTextView.setVisibility(GONE);
}
});
if (mBoomMenuButton.getVisibility() == INVISIBLE)
mBoomMenuButton.setVisibility(VISIBLE);
mBoomMenuButton.boomImmediately();
}
});
}
public BoomMenuButton getBoomMenuButton() {
return mBoomMenuButton;
}
}
<com.tech.futureteric.introui.ui.CustomButton
android:id="@+id/button_sign_up"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="32dp"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:layout_marginStart="32dp"
android:paddingBottom="6dp"
android:paddingTop="6dp"
app:buttonBackground="@drawable/round_button_filled"
app:buttonEnum="textInsideCircle"
app:buttonPlaceEnum="buttonPlace_sc_6_4"
app:buttonText="@string/label_start"
app:buttonTextColor="@color/default_bmb_shareLine1Color"
app:buttonTextSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/button_sign_in"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:piecePlaceEnum="piecePlace_dot_6_4" />
CustomButton customButton = findViewById(R.id.button_sign_up);
BoomMenuButton bmb = customButton.getBoomMenuButton();
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
tools:background="@drawable/round_button">
<!-- TODO change tools:background to see what your button will look like in android studio xml visualizer -->
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
tools:text="@string/label_start"
tools:textColor="@color/default_bmb_shareLine1Color"
tools:textSize="18sp" />
<com.nightonke.boommenu.BoomMenuButton
android:id="@+id/boomMenuButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="-8dp"
android:layout_marginTop="-8dp"
android:visibility="invisible"
app:bmb_backgroundEffect="false"
app:bmb_normalColor="@android:color/transparent" />
</FrameLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment