Custom Dialog
val viewGroup = findViewById<ViewGroup>(android.R.id.content)
// Inflate layout name : custom_alert_dialog
val dialogView = LayoutInflater.from(this).inflate(R.layout.custom_alert_dialog, viewGroup, false)
val builder = AlertDialog.Builder(this)
// set view
builder.setView(dialogView)
val alertDialog = builder.create()
alertDialog.show()
Summary Step
- inflate layout
..
..
- setview
- show
Custom Toast
val toast = Toast.makeText(this, "message", Toast.LENGTH_LONG)
val toastView = toast.view // return the default View of the Toast.
val toastMessage = toastView.findViewById(android.R.id.message) as TextView // find message attibute of toast
toastMessage.textSize = 25f
toastMessage.setTextColor(Color.RED)
// position of drawable (left , top , right , buttom)
toastMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_dialog_alert, 0, 0, 0) << 0 is not show
toastMessage.gravity = Gravity.CENTER
toastMessage.compoundDrawablePadding = 16
toastView.setBackgroundColor(Color.CYAN)
toast.show()
Summary Step
- create new Toast object
..
..
- show
ref :
https://stackoverflow.com/questions/11288475/custom-toast-on-android-a-simple-example
https://www.simplifiedcoding.net/android-custom-dialog-example/