Skip to main content

Posts

Showing posts from April, 2024

How to create custom dialog box in android kotlin

  1=> In Activity File (MainActivity.kt) : override fun onCreate (savedInstanceState: Bundle ?) { super .onCreate(savedInstanceState) setContentView( R . layout . activity_Main ) //method 2 for show dialog box val dialog =Dialog( this ) dialog .setContentView( R . layout . custom_dialog_box ); val btnOk = dialog .findViewById< Button >( R . id . btnOk ) if ( btnOk != null ) { btnOk .setOnClickListener( { Toast .makeText( this , "Success" , Toast . LENGTH_LONG ).show() dialog .dismiss() } )} dialog .show(); //method 2 for show dialog box // // val builder = AlertDialog.Builder(this) // val inflater = LayoutInflater.from(this) // val dialogView = inflater.inflate(R.layout.custom_dialog_box, null) // // builder.setView(dialogView) // // val dialog = builder.create() // dialog.show() } 2=> ...