Skip to content

Instantly share code, notes, and snippets.

@Felipe00
Created May 25, 2017 20:35
Show Gist options
  • Save Felipe00/40fa6fc6899755445499af48b5b10826 to your computer and use it in GitHub Desktop.
Save Felipe00/40fa6fc6899755445499af48b5b10826 to your computer and use it in GitHub Desktop.
Generic dialog with a button and a text
public class DialogBuilder {
/**
* Cria um diálogo com uma mensagem personalizada
*
* @param context
* @param message
*/
public static void createGenericErrorDialog(Context context, String message) {
final Dialog errorDialog = new Dialog(context);
errorDialog.setTitle(R.string.main_dialog_wait);
errorDialog.setContentView(R.layout.meu_dialog_personalizado);
final Button btnOK = (Button) errorDialog.findViewById(R.id.dialog_generic_bttn_ok);
final TextView txtvMSG = (TextView) errorDialog.findViewById(R.id.dialog_generic_msg);
txtvMSG.setText(message);
btnOK.setText(android.R.string.ok);
btnOK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
errorDialog.dismiss();
}
});
errorDialog.show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/dialog_generic_msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="8dp"
android:textSize="17sp"
android:textStyle="bold" />
<Button
android:id="@+id/dialog_generic_bttn_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="32dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:textSize="16sp" />
</LinearLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment