Skip to content

Instantly share code, notes, and snippets.

@reuniware
Last active July 5, 2019 11:57
Show Gist options
  • Save reuniware/96dea0650fb57d1185e192805547e03f to your computer and use it in GitHub Desktop.
Save reuniware/96dea0650fb57d1185e192805547e03f to your computer and use it in GitHub Desktop.
Alertdialog Kotlin in Fragment (with same theme as the default theme when showing from normal Activity)
var alertDialogBuilder = AlertDialog.Builder(context, R.style.AlertDialogThemeCustom)
alertDialogBuilder.setTitle("Deletion")
alertDialogBuilder.setMessage("Do you confirm the deletion ?")
alertDialogBuilder.setCancelable(false)
alertDialogBuilder.setPositiveButton("Yes, delete", DialogInterface.OnClickListener { dialog, which ->
// ...
dialog.cancel()
} )
alertDialogBuilder.setNegativeButton("No, cancel", DialogInterface.OnClickListener { dialog, which ->
// Do nothing
} )
val alertDialog = alertDialogBuilder.create()
alertDialog.show()
/*
<style name="AlertDialogThemeCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColor">@color/alertdialog_black</item>
<item name="android:windowBackground">@color/alertdialog_whitegrey</item>
</style>
<color name="alertdialog_black">#FF000000</color>
<color name="alertdialog_whitegrey">#FFF2F2F2</color>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment