Skip to content

Instantly share code, notes, and snippets.

@Jayin
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save Jayin/f1d0b20168208600e7da to your computer and use it in GitHub Desktop.

Select an option

Save Jayin/f1d0b20168208600e7da to your computer and use it in GitHub Desktop.
Qustom helps you make quick custom dialogs for Android. From https://github.com/danoz73/QustomDialog

Usage

QustomDialogBuilder qustomDialogBuilder = new QustomDialogBuilder(context).
		setTitle("Set IP Address").
		setTitleColor("#FF00FF").
		setDividerColor("#FF00FF").
		setMessage("You are now entering the 10th dimension.").

qustomDialogBuilder.show();

QustomDialog is really just a single class (QustomDialogBuild.java) in addition to one layout file ('qustom_dialog_layout.xml'). You can plug these into your project and use it in its simplest form as shown above. If you have the need for more complex layouts other than just a simple message, you can set custom views as shown below (it references an example layout example_ip_address_layout.xml).

QustomDialogBuilder qustomDialogBuilder = new QustomDialogBuilder(context).
		setTitle("Set IP Address").
		setTitleColor("#FF00FF").
		setDividerColor("#FF00FF").
		setMessage("You are now entering the 10th dimension.").
		setCustomView(R.layout.example_ip_address_layout, context).
		setIcon(getResources().getDrawable(R.drawable.ic_launcher));

qustomDialogBuilder.show();
package com.qustom.dialog;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.qustom.dialog.R;
public class QustomDialogBuilder extends AlertDialog.Builder{
/** The custom_body layout */
private View mDialogView;
/** optional dialog title layout */
private TextView mTitle;
/** optional alert dialog image */
private ImageView mIcon;
/** optional message displayed below title if title exists*/
private TextView mMessage;
/** The colored holo divider. You can set its color with the setDividerColor method */
private View mDivider;
public QustomDialogBuilder(Context context) {
super(context);
mDialogView = View.inflate(context, R.layout.qustom_dialog_layout, null);
setView(mDialogView);
mTitle = (TextView) mDialogView.findViewById(R.id.alertTitle);
mMessage = (TextView) mDialogView.findViewById(R.id.message);
mIcon = (ImageView) mDialogView.findViewById(R.id.icon);
mDivider = mDialogView.findViewById(R.id.titleDivider);
}
/**
* Use this method to color the divider between the title and content.
* Will not display if no title is set.
*
* @param colorString for passing "#ffffff"
*/
public QustomDialogBuilder setDividerColor(String colorString) {
mDivider.setBackgroundColor(Color.parseColor(colorString));
return this;
}
@Override
public QustomDialogBuilder setTitle(CharSequence text) {
mTitle.setText(text);
return this;
}
public QustomDialogBuilder setTitleColor(String colorString) {
mTitle.setTextColor(Color.parseColor(colorString));
return this;
}
@Override
public QustomDialogBuilder setMessage(int textResId) {
mMessage.setText(textResId);
return this;
}
@Override
public QustomDialogBuilder setMessage(CharSequence text) {
mMessage.setText(text);
return this;
}
@Override
public QustomDialogBuilder setIcon(int drawableResId) {
mIcon.setImageResource(drawableResId);
return this;
}
@Override
public QustomDialogBuilder setIcon(Drawable icon) {
mIcon.setImageDrawable(icon);
return this;
}
/**
* This allows you to specify a custom layout for the area below the title divider bar
* in the dialog. As an example you can look at example_ip_address_layout.xml and how
* I added it in TestDialogActivity.java
*
* @param resId of the layout you would like to add
* @param context
*/
public QustomDialogBuilder setCustomView(int resId, Context context) {
View customView = View.inflate(context, resId, null);
((FrameLayout)mDialogView.findViewById(R.id.customPanel)).addView(customView);
return this;
}
@Override
public AlertDialog show() {
if (mTitle.getText().equals("")) mDialogView.findViewById(R.id.topPanel).setVisibility(View.GONE);
return super.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment