Skip to content

Instantly share code, notes, and snippets.

Created May 10, 2017 17:37
Show Gist options
  • Save anonymous/34edc1afbdb7e9d10d9adbda63d4cd8c to your computer and use it in GitHub Desktop.
Save anonymous/34edc1afbdb7e9d10d9adbda63d4cd8c to your computer and use it in GitHub Desktop.
This is how you create the dialogs I showed in the screenshots
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
switch (which)
{
case DialogInterface.BUTTON_POSITIVE:
Log.d("TAG", "User pressed start");
break;
case DialogInterface.BUTTON_NEGATIVE:
dialog.dismiss();
break;
}
}
};
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
//Normal AlertDialog
new AlertDialog.Builder(this)
.setView(inflater.inflate(R.layout.content, null))
.setTitle("Start a new ai game?")
.setPositiveButton("Start", dialogClickListener)
.setNegativeButton("Close", dialogClickListener);
//My AlertDialog
new AlertDialog.Builder(this)
.setCustomTitle(inflater.inflate(R.layout.title,null)) //The title's TextView's style should be the
// same as the the one of the dialog normal AlertDialog's Title Style (see example above)
.setView(inflater.inflate(R.layout.content, null))
.setPositiveButton("Start", dialogClickListener)
.setNegativeButton("Close", dialogClickListener)
.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment