[英]How to customize Alert Dialog buttons like in Google Photos App
我如何實現像這樣的“警報對話框按鈕”樣式:
我必須創建自定義“對話框”還是可以通過AlertDialog主題實現?
您可以像創建普通活動屏幕一樣自定義對話框屏幕,但是您可以使用該庫搜索其他對話框屏幕。
您應該使用該庫進行漂亮的對話框
只需使用具有自定義樣式的MaterialAlertDialogBuilder
:
new MaterialAlertDialogBuilder(MainActivity.this,
R.style.MyThemeOverlay_MaterialComponents_MaterialAlertDialog)
.setTitle("Keep backup off?")
.setMessage("Backup is free and unlimited at high quality")
.setPositiveButton("Turn on", null)
.setNegativeButton("Keep off", /* listener = */ null)
.show();
使用buttonBarPositiveButtonStyle
和buttonBarNegativeButtonStyle
屬性更改默認顏色。
在這種情況下,您可以將填充按鈕 ( Widget.MaterialComponents.Button
)用於正按鈕,將文本按鈕 ( Widget.MaterialComponents.Button.TextButton.Dialog
)用於負按鈕。
<style name="MyThemeOverlay.MaterialComponents.MaterialAlertDialog" parent="@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
<item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
</style>
<style name="PositiveButtonStyle" parent="@style/Widget.MaterialComponents.Button">
<item name="android:textColor">#FFFFFF</item>
<item name="backgroundTint">@color/primaryDarkColor</item>
</style>
<style name="NegativeButtonStyle" parent="@style/Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">@color/primaryDarkColor</item>
</style>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.