Another variant
Resources \ Values \ styles.xml
<style name="MessageDialog" parent="android:Theme.Holo.Light.Dialog"> <item name="android:windowBackground">@android:color/transparent</item> </style>
Where
AlertDialog.Builder builder = new AlertDialog.Builder(Activity, Resource.Style.MessageDialog);
These statements are written from the following passage:
public class MessageAlertDialog : DialogFragment, IDialogInterfaceOnClickListener { private const string DIALOG_TITLE = "dialogTitle"; private const string MESSAGE_TEXT = "messageText"; private const string MESSAGE_RESOURCE_ID = "messageResourceId"; private string _dialogTitle; private string _messageText; private int _messageResourceId; public EventHandler OkClickEventHandler { get; set; } public static MessageAlertDialog NewInstance(string messageText) { MessageAlertDialog dialogFragment = new MessageAlertDialog(); Bundle args = new Bundle(); args.PutString(MESSAGE_TEXT, messageText); dialogFragment.Arguments = args; return dialogFragment; } public static MessageAlertDialog NewInstance(string dialogTitle, string messageText) { MessageAlertDialog dialogFragment = new MessageAlertDialog(); Bundle args = new Bundle(); args.PutString(DIALOG_TITLE, dialogTitle); args.PutString(MESSAGE_TEXT, messageText); dialogFragment.Arguments = args; return dialogFragment; } public static MessageAlertDialog NewInstance(int messageResourceId) { MessageAlertDialog dialogFragment = new MessageAlertDialog(); Bundle args = new Bundle(); args.PutInt(MESSAGE_RESOURCE_ID, messageResourceId); dialogFragment.Arguments = args; return dialogFragment; } public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); _dialogTitle = Arguments.GetString(DIALOG_TITLE); _messageText = Arguments.GetString(MESSAGE_TEXT); _messageResourceId = Arguments.GetInt(MESSAGE_RESOURCE_ID); } public override Dialog OnCreateDialog(Bundle savedInstanceState) { base.OnCreateDialog(savedInstanceState); AlertDialog.Builder builder = new AlertDialog.Builder(Activity, Resource.Style.MessageDialog); if (_dialogTitle != null) { builder.SetTitle(_dialogTitle); } if (_messageText != null) { builder.SetMessage(_messageText); } else { View messageView = GetMessageView(); if (messageView != null) { builder.SetView(messageView); } } builder.SetPositiveButton("OK", this);
Using
public static void ShowMessageAlertDialog(FragmentManager fragmentManager, string dialogTitle, string messageText, EventHandler okClickEventHandler) { MessageAlertDialog msgAlertDialog = MessageAlertDialog.NewInstance(dialogTitle, messageText); msgAlertDialog.OkClickEventHandler += okClickEventHandler; msgAlertDialog.Show(fragmentManager, "message_alert_dialog"); }
samusarin Jul 26 '17 at 2:56 p.m. 2017-07-26 14:56
source share