DisplayActionSheet() 没有将销毁按钮放在 Android 的顶部

DisplayActionSheet() doesn't put the destruction button at the top in Android

我有以下代码

string actCancel = "Cancel";
string actDelete = "Delete it";
string actRename = "Rename it";
string action = await DisplayActionSheet($"What do you want to do? \n {pickerSystem.SelectedItem}", actCancel, actDelete, actRename);

我希望显示看起来与 https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/pop-ups Guide users through tasks. But it does not, it looks like 下的第二个示例非常相似。

用户的选择有些分散,不像文档示例那样整齐排列。我做错了什么还是我的期望有误? (VS2019 Windows, Android Pixel2模拟器)

因为您只提供了一个操作,即 actRenameparams string[] buttons 参数,在您的代码中,您已将 actDelete 分配给 destruction 参数。

您需要将参数 destruction 指定为 null 是您没有使用它:

string actCancel = "Cancel";
string actDelete = "Delete it";
string actRename = "Rename it";
string action = await DisplayActionSheet($"What do you want to do? \n {pickerSystem.SelectedItem}",
                                        actCancel, null, actDelete, actRename);

这是DisplayActionSheet() API definition


编辑

Xamarin.Forms 正在为 DisplayActionSheet()here is the code responsible to create the destruction Button, as you can see it is just mapping it to the native "negative button" of the dialog using SetNegativeButton().

使用原生 Android 对话框

本机 Android 对话框具有描述的布局 here and Material ones here

“否定按钮”在“肯定按钮”的左侧。

因此,要实现您附加的 link 中的屏幕截图,您可能需要创建一个自定义本机弹出窗口。


更新

文档中令人困惑的屏幕截图已更新:

问题:https://github.com/MicrosoftDocs/xamarin-docs/issues/3253#event-4401694274

更新页面:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/pop-ups#guide-users-through-tasks