Android AlertDialog setView,kotlin

Android AlertDialog setView,kotlin

 




    

 

 

import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val alertDialog: AlertDialog = AlertDialog.Builder(this).create()
        alertDialog.setTitle("my title")

        val view = LayoutInflater.from(this).inflate(R.layout.input_layout, null, false)
        alertDialog.setView(view)

        alertDialog.setButton(
            DialogInterface.BUTTON_POSITIVE,
            "ok",
            fun(dialog: DialogInterface, which: Int) {
                dialog.dismiss()
            }
        )

        alertDialog.setButton(
            DialogInterface.BUTTON_NEGATIVE,
            "cancel",
            fun(dialog: DialogInterface, which: Int) {
                dialog.dismiss()
            }
        )

        alertDialog.show()
    }
}

 

 

 

Android DialogFragment(1)_zhangphil的博客-CSDN博客Android DialogFragment(1)和过去的AlertDialog类似,Android引入的DialogFragment旨在为开发者提供一个“富”dialog,而不必受到过去Android AlertDialog的局限。首先,DialogFragment是一个Fragment,它有Fragment的一切属性和生命周期,其次,DialogFragment具有和AlertDihttps://blog.csdn.net/zhangphil/article/details/50886077

Android DialogFragment(2)_zhangphil的博客-CSDN博客Android DialogFragment(2)附录文章1简单介绍了如何实现一个DialogFragment,本文再介绍一种简单的方法:直接重写DialogFragment的onCreateDialog返回一个AlertDialog实现对话框。本文的例子和附录文章1不同的地方:不在依赖onCreateView。代码运行逻辑简述:功能简单,当点击FloatingActionButthttps://blog.csdn.net/zhangphil/article/details/50923828

Android Activity调整改变成Dialog_activity改成dialog_zhangphil的博客-CSDN博客做一个style配置到style.xml,直接作为该Activity的android:theme配置即可。具体的style: <style name="DialogActivity" parent="@style/Theme.AppCompat.Dialog"> <item name="android:windowFullscreen">true<...https://blog.csdn.net/zhangphil/article/details/80258149

 

你可能感兴趣的:(kotlin,Android,android,kotlin)