[Kotlin] AlertDialogをカスタマイズする

AlertBuilderでAlertDialogをカスタマイズします。（カスタムレイアウト作成した方がおすすめですが）

・標準のAlertDialog
<img width="637" alt="Screen Shot 2019-05-17 at 17.51.55.png" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/418478/a8d2edbf-b71a-5512-a057-f8844c769223.png">

・成果物
<img width="636" alt="Screen Shot 2019-05-17 at 17.51.41.png" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/418478/0258cc5f-c169-340e-c47d-feefce1c114e.png">

## ソースコード
```kotlin:AlertDialogFragment.kt

// 省略

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {

    // ダイアログのタイトルのカスタマイズ
    val text = TextView(context)
    text.text = "Error"
    text.setPadding(0, 25, 0, 25)
    text.textSize = 20F
    text.textAlignment = View.TEXT_ALIGNMENT_CENTER
    text.setTextColor(resources.getColor(R.color.white, null))
    text.background = resources.getDrawable(R.color.green, null)

    val builder = activity?.let { AlertDialog.Builder(it) }
    
    // setTitleではなくsetCustomTitleを使う
    builder!!.setCustomTitle(text)
            .setMessage(message)
            .setPositiveButton(okButtonName, onOkClickListener)

    val dialog = builder.show()

    // OKボタンを中央揃えに
    val button = dialog.getButton(DialogInterface.BUTTON_POSITIVE)
    button.gravity = Gravity.CENTER
    button.setTextColor(resources.getColor(R.color.colorWhite, null))
    button.setPadding(0, -30, 0, -30)
    button.background = resources.getDrawable(R.drawable.green_button, null)
    button.textSize = 15F

    val layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 55)
    layoutParams.gravity = Gravity.CENTER
    layoutParams.marginStart = 250
    layoutParams.marginEnd = 250
    layoutParams.topMargin = 20
    layoutParams.bottomMargin = 15
    button.layoutParams = layoutParams

    this.isCancelable = false

    return dialog
}
```

## 二つ以上のボタンがある時

```kotlin:AlertDialogFragment.kt

// 省略

        builder!!.setCustomTitle(text)
                .setMessage(message)
                .setPositiveButton("OK",onOkClickListener)
                .setNegativeButton("CANCEL",onCancelClickListener)
                .setOnDismissListener(onDismissListener)

        val dialog = builder.show()

        val okButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE)
        okButton.gravity = Gravity.CENTER
        okButton.setTextColor(resources.getColor(R.color.white, null))
        okButton.setPadding(70, -30, 70, -30)
        okButton.background = resources.getDrawable(R.drawable.green_button, null)
        okButton.textSize = 15F

        val layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 55)
        layoutParams.gravity = Gravity.CENTER
        layoutParams.marginStart = 30
        layoutParams.marginEnd = 160
        layoutParams.topMargin = 20
        layoutParams.bottomMargin = 10
        okButton.layoutParams = layoutParams

        val cancelButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE)
        cancelButton.gravity = Gravity.CENTER
        cancelButton.setTextColor(resources.getColor(R.color.green, null))
        cancelButton.setPadding(50, -30, 50, -30)
        cancelButton.textSize = 15F

        val layoutParams2 = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 55)
        layoutParams2.gravity = Gravity.CENTER
        layoutParams2.marginStart = 60
        layoutParams2.marginEnd = 30
        layoutParams2.topMargin = 20
        layoutParams2.bottomMargin = 10
        cancelButton.layoutParams = layoutParams2

// 省略
```
####成果物
<img width="656" alt="Screen Shot 2019-05-17 at 17.51.49.png" src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/418478/8147fd9b-a5d2-67da-bd80-6a2211d78531.png">

##ダイアログ表示方法
Fragmentでカスタムダイアログを表示したい時の例です。ご参考してください。

```
val dialog = AlertDialogFragment()
dialog.title = getString("Error")
dialog.message = getString("XXXXXXXXXXXXXXXXXX")
dialog.onOkClickListener = DialogInterface.OnClickListener { _, _ ->
　　// OK押したらなんかする
dialog.show(childFragmentManager, "")
```