簡體   English   中英

如何自定義“警報對話框”按鈕,例如在Google相冊應用中

[英]How to customize Alert Dialog buttons like in Google Photos App

我如何實現像這樣的“警報對話框按鈕”樣式:

Google相簿應用程式

我必須創建自定義“對話框”還是可以通過AlertDialog主題實現?

您可以像創建普通活動屏幕一樣自定義對話框屏幕,但是您可以使用庫搜索其他對話框屏幕。

您應該使用該庫進行漂亮的對話框

https://github.com/pedant/sweet-alert-dialog

只需使用具有自定義樣式的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();

使用buttonBarPositiveButtonStylebuttonBarNegativeButtonStyle屬性更改默認顏色。
在這種情況下,您可以將填充按鈕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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM