AlertDialog 的介紹
- AlertDialog的方法
返回值 | 方法名 |
---|---|
open Button! | getButton(whichButton: Int) 獲獲取對話框中使用的按鈕之一。如果指定的按鈕不存在或?qū)υ捒蛏形赐耆珓?chuàng)建(例如,通過 show() 或 create()),則返回 null。取dialog中某個(gè)按鈕, whichButton 可選的值: DialogInterface.BUTTON_POSITIVE ,DialogInterface.BUTTON_NEGATIVE ,DialogInterface.BUTTON_NEUTRAL(這是最左側(cè)的按鈕) |
open ListView! | getListView() 獲取對話框中使用的列表視圖。 |
open Boolean | onKeyDown(keyCode: Int, event: KeyEvent) 按下某個(gè)鍵 |
open Boolean | onKeyUp(keyCode: Int, event: KeyEvent) 抬起某個(gè)鍵 |
open Unit | setButton(whichButton: Int, text: CharSequence!, msg: Message!)設(shè)置按下按鈕時(shí)要發(fā)送的消息。如果在 show() 之后調(diào)用此方法則無效。 |
open Unit | setButton(whichButton: Int, text: CharSequence!, listener: OnClickListener!)設(shè)置在按下對話框的正按鈕時(shí)要調(diào)用的偵聽器。如果在 show() 之后調(diào)用此方法則無效。 |
open Unit | setButton(whichButton: Int, text: CharSequence!, icon: Drawable!, listener: OnClickListener!)設(shè)置要與按鈕文本一起顯示的圖標(biāo)以及在按下對話框的正按鈕時(shí)要調(diào)用的偵聽器。如果在 show() 之后調(diào)用此方法則無效。 |
open Unit | setCustomTitle(customTitleView: View!)設(shè)置自定義的title 如果在 show() 之后調(diào)用此方法則無效。 |
open Unit | setIcon(resId: Int) 設(shè)置icon,如果不想要icon將resId設(shè)置為0 |
open Unit | setIcon(icon: Drawable!) 設(shè)置要在標(biāo)題中使用的 Drawable。 |
open Unit | setIconAttribute(attrId: Int)設(shè)置由主題屬性提供的圖標(biāo)。例如android.R.attr.alertDialogIcon |
open Unit | setMessage(message: CharSequence!)設(shè)置要顯示的消息。 |
open Unit | setTitle(title: CharSequence?) 設(shè)置標(biāo)題 |
open Unit | setView(view: View!)設(shè)置要在對話框中顯示的視圖。如果在 show() 之后調(diào)用此方法則無效。 |
open Unit | setView(view: View!, viewSpacingLeft: Int, viewSpacingTop: Int, viewSpacingRight: Int, viewSpacingBottom: Int)設(shè)置要在對話框中顯示的視圖,指定在該視圖周圍顯示的間距。如果在 show() 之后調(diào)用此方法則無效。 |
- AlertDialog的創(chuàng)建
AlertDialog的構(gòu)造函數(shù)都是protected的,因此我們無法直接通過構(gòu)造函數(shù)實(shí)例化,所以SDK提供了 AlertDialog.Builder這個(gè)內(nèi)部類用來創(chuàng)建AlertDialog
構(gòu)造方法 |
---|
Builder(context: Context!) 為使用默認(rèn)警報(bào)對話框主題的警報(bào)對話框創(chuàng)建構(gòu)建器。 默認(rèn)警報(bào)對話框主題由父上下文主題中的 R.attr.alertDialogTheme 定義。 |
Builder(context: Context!, themeResId: Int) 為使用顯式主題資源的警報(bào)對話框創(chuàng)建構(gòu)建器。 指定的主題資源 (themeResId) 應(yīng)用于父上下文的主題之上。它可以指定為包含完全填充主題的樣式資源,例如 R.style.Theme_Material_Dialog,以替換父上下文主題中的所有屬性,包括主色和強(qiáng)調(diào)色。 為了保留諸如主色和強(qiáng)調(diào)色之類的屬性,themeResId 可以改為指定為覆蓋主題,例如 R.style.ThemeOverlay_Material_Dialog。這將僅覆蓋將警報(bào)窗口樣式化為對話框所需的窗口屬性。 或者,可以將 themeResId 指定為 0 以使用 R.attr.alertDialogTheme 的父上下文解析值。 |
返回值 | 方法名 |
---|---|
open AlertDialog! | create()使用提供給此構(gòu)建器的參數(shù)創(chuàng)建 AlertDialog。 調(diào)用此方法不會(huì)顯示對話框。如果不需要額外的處理,可以調(diào)用 show() 來創(chuàng)建和顯示對話框。 |
open Context! | getContext()為由此生成器創(chuàng)建的對話框返回具有適當(dāng)主題的上下文。應(yīng)用程序應(yīng)該使用這個(gè) Context 來獲取 LayoutInflaters 來膨脹將在結(jié)果對話框中使用的視圖,因?yàn)樗鼤?huì)導(dǎo)致視圖用正確的主題膨脹。 |
open AlertDialog.Builder! | setAdapter(adapter: ListAdapter!, listener: DialogInterface.OnClickListener!)設(shè)置由給定 ListAdapter 提供的項(xiàng)目列表作為內(nèi)容顯示在對話框中,您將通過提供的偵聽器收到所選項(xiàng)目的通知。 |
open AlertDialog.Builder! | setCancelable(cancelable: Boolean)設(shè)置對話框是否可取消。默認(rèn)為true。 |
open AlertDialog.Builder! | setCursor(cursor: Cursor!, listener: DialogInterface.OnClickListener!, labelColumn: String!)設(shè)置由給定 Cursor 提供的項(xiàng)目列表,作為內(nèi)容顯示在對話框中,您將通過提供的偵聽器收到所選項(xiàng)目的通知。 |
open AlertDialog.Builder! | setCustomTitle(customTitleView: View!)使用自定義視圖 customTitleView 設(shè)置標(biāo)題。 方法 setTitle(int) 和 setIcon(int) 應(yīng)該足以滿足大多數(shù)標(biāo)題,但如果標(biāo)題需要更多自定義,則提供此方法。使用這將替換通過其他方法設(shè)置的標(biāo)題和圖標(biāo)。 注意:為了確保樣式一致,自定義視圖應(yīng)該使用通過 getContext() 獲得的警報(bào)對話框的主題上下文來膨脹或構(gòu)造。 |
open AlertDialog.Builder! | setIcon(iconId: Int)設(shè)置要在標(biāo)題中使用的 Drawable 的資源 ID。 優(yōu)先于使用 setIcon(android.graphics.drawable.Drawable) 設(shè)置的值 |
open AlertDialog.Builder! | setIcon(icon: Drawable!)設(shè)置要在標(biāo)題中使用的 Drawable。 注意:為確保樣式一致,應(yīng)使用通過 getContext() 獲取的警報(bào)對話框的主題上下文來擴(kuò)充或構(gòu)造可繪制對象。 |
open AlertDialog.Builder! | setIconAttribute(attrId: Int)設(shè)置由主題屬性提供的圖標(biāo)。例如android.R.attr#alertDialogIcon。 優(yōu)先于使用 setIcon(int) 或 setIcon(android.graphics.drawable.Drawable) 設(shè)置的值 |
open AlertDialog.Builder! | setInverseBackgroundForced(useInverseBackground: Boolean)將警報(bào)對話框設(shè)置為使用反向背景,無論內(nèi)容是什么。(已棄用:此標(biāo)志僅用于之前的 Material主題。相反,使用警報(bào)對話框主題指定窗口背景。) |
open AlertDialog.Builder! | setItems(itemsId: Int, listener: DialogInterface.OnClickListener!)設(shè)置要在對話框中顯示的項(xiàng)目列表作為內(nèi)容,您將通過提供的偵聽器收到所選項(xiàng)目的通知。這應(yīng)該是一個(gè)數(shù)組類型,即 R.array.foo |
open AlertDialog.Builder! | setItems(items: Array<CharSequence!>!, listener: DialogInterface.OnClickListener!)設(shè)置要在對話框中顯示的項(xiàng)目列表作為內(nèi)容,您將通過提供的偵聽器收到所選項(xiàng)目的通知。 |
open AlertDialog.Builder! | setMessage(messageId: Int) 使用給定的資源 ID 設(shè)置要顯示的消息。 |
open AlertDialog.Builder! | setMessage(message: CharSequence!)設(shè)置要顯示的消息。 |
open AlertDialog.Builder! | setMultiChoiceItems(itemsId: Int, checkedItems: BooleanArray!, listener: DialogInterface.OnMultiChoiceClickListener!)設(shè)置要在對話框中顯示的項(xiàng)目列表作為內(nèi)容,您將通過提供的偵聽器收到所選項(xiàng)目的通知。這應(yīng)該是一個(gè)數(shù)組類型,例如R.array.foo。該列表將在每個(gè)選中項(xiàng)目的文本右側(cè)顯示一個(gè)復(fù)選標(biāo)記。單擊列表中的項(xiàng)目不會(huì)關(guān)閉對話框。單擊按鈕將關(guān)閉對話框。 |
open AlertDialog.Builder! | setMultiChoiceItems(items: Array<CharSequence!>!, checkedItems: BooleanArray!, listener: DialogInterface.OnMultiChoiceClickListener!)設(shè)置要在對話框中顯示的項(xiàng)目列表作為內(nèi)容,您將通過提供的偵聽器收到所選項(xiàng)目的通知。該列表將在每個(gè)選中項(xiàng)目的文本右側(cè)顯示一個(gè)復(fù)選標(biāo)記。單擊列表中的項(xiàng)目不會(huì)關(guān)閉對話框。單擊按鈕將關(guān)閉對話框。 |
open AlertDialog.Builder! | setMultiChoiceItems(cursor: Cursor!, isCheckedColumn: String!, labelColumn: String!, listener: DialogInterface.OnMultiChoiceClickListener!)設(shè)置要在對話框中顯示的項(xiàng)目列表作為內(nèi)容,您將通過提供的偵聽器收到所選項(xiàng)目的通知。該列表將在每個(gè)選中項(xiàng)目的文本右側(cè)顯示一個(gè)復(fù)選標(biāo)記。單擊列表中的項(xiàng)目不會(huì)關(guān)閉對話框。單擊按鈕將關(guān)閉對話框。 |
open AlertDialog.Builder! | setNegativeButton(textId: Int, listener: DialogInterface.OnClickListener!)設(shè)置在按下對話框的Negative按鈕時(shí)要調(diào)用的偵聽器。 |
open AlertDialog.Builder! | setNegativeButton(text: CharSequence!, listener: DialogInterface.OnClickListener!)設(shè)置在按下對話框的Negative按鈕時(shí)要調(diào)用的偵聽器。 |
open AlertDialog.Builder! | setNeutralButton(textId: Int, listener: DialogInterface.OnClickListener!)設(shè)置在按下對話框的Neutral按鈕時(shí)要調(diào)用的偵聽器。 |
open AlertDialog.Builder! | setNeutralButton(text: CharSequence!, listener: DialogInterface.OnClickListener!)設(shè)置在按下對話框的Neutral按鈕時(shí)要調(diào)用的偵聽器。 |
open AlertDialog.Builder! | setOnCancelListener(onCancelListener: DialogInterface.OnCancelListener!)設(shè)置在對話框取消時(shí)將調(diào)用的回調(diào)。 即使在可取消的對話框中,對話框也可能由于被取消或提供的選項(xiàng)之一被選擇以外的原因而被關(guān)閉。如果您有興趣偵聽對話框被關(guān)閉的所有情況,而不僅僅是在取消時(shí),請參閱 setOnDismissListener |
open AlertDialog.Builder! | setOnDismissListener(onDismissListener: DialogInterface.OnDismissListener!)設(shè)置在對話框因任何原因關(guān)閉時(shí)將調(diào)用的回調(diào)。 |
open AlertDialog.Builder! | setOnItemSelectedListener(listener: AdapterView.OnItemSelectedListener!)設(shè)置在選擇列表中的項(xiàng)目時(shí)要調(diào)用的偵聽器。 |
open AlertDialog.Builder! | setOnKeyListener(onKeyListener: DialogInterface.OnKeyListener!)設(shè)置將在將key分派到對話框時(shí)調(diào)用的回調(diào)。 |
open AlertDialog.Builder! | setPositiveButton(textId: Int, listener: DialogInterface.OnClickListener!)設(shè)置在按下對話框的Positive按鈕時(shí)要調(diào)用的偵聽器。 |
open AlertDialog.Builder! | setPositiveButton(text: CharSequence!, listener: DialogInterface.OnClickListener!)設(shè)置在按下對話框的Positive按鈕時(shí)要調(diào)用的偵聽器。 |
open AlertDialog.Builder! | setSingleChoiceItems(itemsId: Int, checkedItem: Int, listener: DialogInterface.OnClickListener!)設(shè)置要在對話框中顯示的項(xiàng)目列表作為內(nèi)容,您將通過提供的偵聽器收到所選項(xiàng)目的通知。這應(yīng)該是一個(gè)數(shù)組類型,即 R.array.foo 該列表將在選中項(xiàng)的文本右側(cè)顯示一個(gè)復(fù)選標(biāo)記。單擊列表中的項(xiàng)目不會(huì)關(guān)閉對話框。單擊按鈕將關(guān)閉對話框。 |
open AlertDialog.Builder! | setSingleChoiceItems(cursor: Cursor!, checkedItem: Int, labelColumn: String!, listener: DialogInterface.OnClickListener!)設(shè)置要在對話框中顯示的項(xiàng)目列表作為內(nèi)容,您將通過提供的偵聽器收到所選項(xiàng)目的通知。該列表將在選中項(xiàng)目的文本右側(cè)顯示一個(gè)復(fù)選標(biāo)記。單擊列表中的項(xiàng)目不會(huì)關(guān)閉對話框。單擊按鈕將關(guān)閉對話框。 |
open AlertDialog.Builder! | setSingleChoiceItems(items: Array<CharSequence!>!, checkedItem: Int, listener: DialogInterface.OnClickListener!)設(shè)置要在對話框中顯示的項(xiàng)目列表作為內(nèi)容,您將通過提供的偵聽器收到所選項(xiàng)目的通知。該列表將在選中項(xiàng)目的文本右側(cè)顯示一個(gè)復(fù)選標(biāo)記。單擊列表中的項(xiàng)目不會(huì)關(guān)閉對話框。單擊按鈕將關(guān)閉對話框。 |
open AlertDialog.Builder! | setSingleChoiceItems(adapter: ListAdapter!, checkedItem: Int, listener: DialogInterface.OnClickListener!)設(shè)置要在對話框中顯示的項(xiàng)目列表作為內(nèi)容,您將通過提供的偵聽器收到所選項(xiàng)目的通知。該列表將在選中項(xiàng)目的文本右側(cè)顯示一個(gè)復(fù)選標(biāo)記。單擊列表中的項(xiàng)目不會(huì)關(guān)閉對話框。單擊按鈕將關(guān)閉對話框。. |
open AlertDialog.Builder! | setTitle(titleId: Int)使用給定的資源 ID 設(shè)置標(biāo)題。 |
open AlertDialog.Builder! | setTitle(title: CharSequence!)設(shè)置對話框中顯示的標(biāo)題。 |
open AlertDialog.Builder! | setView(layoutResId: Int)將自定義視圖資源設(shè)置為對話框的內(nèi)容。資源將被膨脹,將所有頂級視圖添加到屏幕上。 |
open AlertDialog.Builder! | setView(view: View!)將自定義視圖設(shè)置為警報(bào)對話框的內(nèi)容。 使用前 Holo 主題時(shí),如果提供的視圖是 ListView 的實(shí)例,則將使用淺色背景。 注意:為了確保樣式一致,自定義視圖應(yīng)該使用通過 getContext() 獲得的警報(bào)對話框的主題上下文來膨脹或構(gòu)造。 |
open AlertDialog! | show()使用提供給此構(gòu)建器的參數(shù)創(chuàng)建 AlertDialog 并立即顯示對話框。 |
//Theme.AppCompat.Dialog主題常用的一般有以下屬性:
<!-- 背景透明 -->
<item name="android:windowBackground">@android:color/transparent</item>
<!-- 邊框 -->
<item name="android:windowFrame">@null</item>
<!-- 是否浮現(xiàn)在activity之上 -->
<item name="android:windowIsFloating">true</item>
<!-- 是否半透明 -->
<item name="android:windowIsTranslucent">true</item>
<!-- 是否無標(biāo)題 -->
<item name="android:windowNoTitle">true</item>
<!-- Dialog背景樣式 -->
<item name="android:background">@android:color/transparent</item>
<!-- 模糊 -->
<item name="android:backgroundDimEnabled">true</item>
<!-- 遮罩層 -->
<item name="android:backgroundDimAmount">0.5</item>
<!-- Dialog的寬度和屏幕的比例 -->
<item name="android:windowMinWidthMinor">80%</item>
<!-- Dialog的最小寬度 -->
<item name="android:minWidth">300dp</item>
<!-- Dialog的最小高度 -->
<item name="android:minHeight">200dp</item>
AlertDialog 的使用
1.提示對話框
val builder = AlertDialog.Builder(this)
builder.setTitle("Title")
builder.setMessage("Message")
//設(shè)置Neutral按鈕(最左邊的按鈕)
builder.setNeutralButton("Neutral") { _, _ ->
Toast.makeText(
this@MainActivity,
"點(diǎn)擊了Neutral",
Toast.LENGTH_SHORT
).show()
}
//設(shè)置Positive按鈕
builder.setPositiveButton("Positive") { _, _ ->
Toast.makeText(
this@MainActivity,
"點(diǎn)擊了Positive",
Toast.LENGTH_SHORT
).show()
}
//設(shè)置Negative按鈕
builder.setNegativeButton("Negative") { _, _ ->
Toast.makeText(
this@MainActivity,
"點(diǎn)擊了Negative",
Toast.LENGTH_SHORT
).show()
}
//設(shè)置在對話框因任何原因關(guān)閉時(shí)將調(diào)用的回調(diào)。
builder.setOnDismissListener {
Toast.makeText(
this@MainActivity,
"對話框Dismiss了",
Toast.LENGTH_SHORT
).show()
}
//設(shè)置在對話框取消時(shí)將調(diào)用的回調(diào)
// builder.setOnCancelListener {
// Toast.makeText(
// this@MainActivity,
// "對話框Cancel了",
// Toast.LENGTH_SHORT
// ).show()
// }
//點(diǎn)擊對話框以外的區(qū)域是否讓對話框消失,默認(rèn)為true;
builder.setCancelable(false)
//設(shè)置對話框的title左邊的圖標(biāo);
builder.setIcon(resources.getDrawable(R.drawable.ic_launcher_background,null))
val dialog = builder.create()
//這個(gè)是Dialog中的方法,builder中沒有這個(gè)方法
dialog.setOnShowListener {
Toast.makeText(
this@MainActivity,
"對話框Show了",
Toast.LENGTH_SHORT
).show()
}
dialog.show()
截屏2021-09-01 上午9.44.28.png
-
列表對話框
val builder = AlertDialog.Builder(this) builder.setCancelable(false) builder.setTitle("這是ListDialog") builder.setIcon(R.mipmap.ic_launcher) builder.setNegativeButton("取消") { _, _ -> Toast.makeText( this@MainActivity, "點(diǎn)擊取消", Toast.LENGTH_SHORT ).show() } builder.setPositiveButton("確定") { _, _ -> Toast.makeText( this@MainActivity, "點(diǎn)擊確定", Toast.LENGTH_SHORT ).show() } val list = arrayOf("語文", "數(shù)學(xué)", "英語", "化學(xué)", "生物", "物理", "體育") //設(shè)置列表 builder.setItems(list) { p0, p1 -> Toast.makeText( this@MainActivity, "點(diǎn)擊了第${p1}行", Toast.LENGTH_SHORT ).show() } builder.create().show()
截屏2021-09-01 上午10.12.04.png
-
單選對話框
val builder = AlertDialog.Builder(this) builder.setCancelable(false) builder.setTitle("這是ListDialog") builder.setIcon(R.mipmap.ic_launcher) builder.setNegativeButton("取消") { _, _ -> Toast.makeText( this@MainActivity, "點(diǎn)擊取消", Toast.LENGTH_SHORT ).show() } builder.setPositiveButton("確定") { _, _ -> Toast.makeText( this@MainActivity, "點(diǎn)擊確定", Toast.LENGTH_SHORT ).show() } val list = arrayOf("語文", "數(shù)學(xué)", "英語", "化學(xué)", "生物", "物理", "體育") //設(shè)置列表 builder.setSingleChoiceItems(list,3) { p0, p1 -> Toast.makeText( this@MainActivity, "點(diǎn)擊了第${p1}行", Toast.LENGTH_SHORT ).show() } builder.create().show()
截屏2021-09-01 上午10.15.53.png
-
多選對話框
val builder = AlertDialog.Builder(this) builder.setCancelable(false) builder.setTitle("這是ListDialog") builder.setIcon(R.mipmap.ic_launcher) builder.setNegativeButton("取消") { _, _ -> Toast.makeText( this@MainActivity, "點(diǎn)擊取消", Toast.LENGTH_SHORT ).show() } builder.setPositiveButton("確定") { _, _ -> Toast.makeText( this@MainActivity, "點(diǎn)擊確定", Toast.LENGTH_SHORT ).show() } val list = arrayOf("語文", "數(shù)學(xué)", "英語", "化學(xué)", "生物", "物理", "體育") var checked = booleanArrayOf(false,false,true,false,false,true,false) //設(shè)置列表 builder.setMultiChoiceItems(list,checked ) { _, p1, p2 -> Toast.makeText( this@MainActivity, "點(diǎn)擊了第${p1}行 $p2", Toast.LENGTH_SHORT ).show() } builder.create().show()
截屏2021-09-01 上午10.29.13.png
-
自定義彈窗
val builder = AlertDialog.Builder(this, R.style.CustomDialog) builder.setCancelable(true) val view = layoutInflater.inflate(R.layout.custom_layout, null, false) val binding = CustomLayoutBinding.bind(view) builder.setView(view) val dialog = builder.create() dialog.show() binding.cancelButton.setOnClickListener { Toast.makeText( this@MainActivity, "點(diǎn)擊了取消", Toast.LENGTH_SHORT ).show() dialog.dismiss() } binding.okButton.setOnClickListener { Toast.makeText( this@MainActivity, "點(diǎn)擊了確認(rèn)", Toast.LENGTH_SHORT ).show() }
custom_layout.xml
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/cancel_button" android:layout_width="100dp" android:layout_height="50dp" android:layout_marginLeft="40dp" android:backgroundTint="#f00" android:text="取消" android:textColor="#0f0" android:textSize="20sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" /> <Button android:id="@+id/ok_button" android:layout_width="100dp" android:layout_height="50dp" android:layout_marginRight="40dp" android:backgroundTint="#0f0" android:text="確定" android:textColor="#f00" android:textSize="20sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" /> <TextView android:id="@+id/message" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_marginTop="60dp" android:gravity="center" android:text="Message" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@id/title" app:layout_constraintBottom_toTopOf="@id/cancel_button" /> <TextView android:id="@+id/title" android:layout_width="0dp" android:layout_height="30dp" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:gravity="center" android:text="標(biāo)題" app:layout_constraintBottom_toTopOf="@id/message" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>
截屏2021-09-01 下午12.09.12.png如何修改Dialog的寬度和高度
直接在layout.xml修改layout_width和layout_height是無法修改Dialog的寬和高的需要自定義一個(gè)theme,使用這個(gè)theme創(chuàng)建AlertDialog.
<style name="CustomDialog" parent="Theme.AppCompat.Dialog"> <!-- dialog 寬度與屏幕比例--> <!-- <item name="android:windowMinWidthMinor">80%</item>--> <!--設(shè)置最小寬度--> <item name="android:minWidth">300dp</item> <!--設(shè)置最小高度--> <item name="android:minHeight">200dp</item> </style>
通過代碼修改AlertDialog的大小
//這段代碼必須放在show()方法之后,否則沒有作用 dialog.window?.setLayout(100,200)
如何修改AlertDialog的位置
//這段代碼必須放在show()方法之前,否則沒有作用 當(dāng)x,y都為0則居中顯示 val para = dialog.window?.attributes para?.x = 100 para?.y = 100