Skip to content

Instantly share code, notes, and snippets.

@delacrixmorgan
Last active March 17, 2019 01:14
Show Gist options
  • Select an option

  • Save delacrixmorgan/6c819debf113feba7c7587f3567f9b01 to your computer and use it in GitHub Desktop.

Select an option

Save delacrixmorgan/6c819debf113feba7c7587f3567f9b01 to your computer and use it in GitHub Desktop.
AlertDialog Single Choice Item, Date Picker

AlertDialog Single Choice Item, Date Picker

https://developer.android.com/training/secure-file-sharing/share-file

AlertDialog Single Choice Item

val arrayString = arrayOf("Aerith", "Tifa", "Vincent", "Sid", "Barret")

this.nameViewGroup.setOnClickListener {
    AlertDialog.Builder(context)
            .setTitle("Choose Party")
            .setSingleChoiceItems(arrayString, 0) { dialog, which ->
                val chosenParty = arrayString[which]
                dialog.dismiss()
            }
            .create()
            .show()

DatePickerDialog

DatePickerDialog(
        context,
        R.style.AppTheme_DatePickerDialogTheme,
        DatePickerDialog.OnDateSetListener { view, year, month, dayOfMonth ->
            val stringDate = "$dayOfMonth/$month/$year"
        },
        currentCalendar.get(Calendar.YEAR),
        currentCalendar.get(Calendar.MONTH),
        currentCalendar.get(Calendar.DAY_OF_MONTH))
        .show()

AlertDialog Styles

<style name="AppTheme.DatePickerDialogTheme" parent="Theme.AppCompat.DayNight.Dialog">
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="buttonBarPositiveButtonStyle">@style/AlertDialogPositiveButton</item>
    <item name="buttonBarNegativeButtonStyle">@style/AlertDialogNegativeButton</item>
</style>

<style name="AlertDialogPositiveButton" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:textStyle">bold</item>
</style>

<style name="AlertDialogNegativeButton" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:textStyle">bold</item>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment