I need to make a AlertDialog
with a custom view.
The message of a AlertDialog
has a default padding but when i set a view it has no padding, i wand to
Just to add a more complete answer of how to use it:
You can use in the layout XML file android:paddingStart="?dialogPreferredPadding"
and android:paddingEnd="?dialogPreferredPadding"
.
Alternatively, if you want to do it by code:
@JvmStatic
fun getDimensionFromAttribute(context: Context, attr: Int): Int {
val typedValue = TypedValue()
return if (context.theme.resolveAttribute(attr, typedValue, true))
TypedValue.complexToDimensionPixelSize(typedValue.data, context.resources.displayMetrics)
else 0
}
usage:
val alertDialogPadding = getDimensionFromAttribute(context, R.attr.dialogPreferredPadding)
view.setPadding(alertDialogPadding, 0, alertDialogPadding, 0)
If you use a CheckBox (and maybe some other views), I don't think it's possible to set the paddings or margins so that it will get aligned nicely with other views in the dialog, unless you wrap it with a different view, or extend it