Вы можете добиться этого поведения, используя Rg.Plugins.Popup , чтобы имитировать c оповещение по умолчанию для отображения, это дает вам больше гибкости в том, как вы хотите, чтобы он выглядел.
Сначала прочитайте Getting Started , на Android вам понадобится это в вашем OnCreate:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Rg.Plugins.Popup.Popup.Init(this, bundle); //Initialize the plugin
Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication (new App ());
}
После этого вам нужно создать View, расширяющийся из PopupPage:
Code Behind:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class AlertPage : PopupPage
{
public AlertPage()
{
InitializeComponent();
}
}
А вот как выглядит Xaml плечо (я попытался максимально приблизить c предупреждение по умолчанию, вы можете настроить его так, чтобы получить желаемый вид) :
<popup:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:popup="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"
xmlns:animations="clr-namespace:Rg.Plugins.Popup.Animations;assembly=Rg.Plugins.Popup"
x:Class="BlankAppTest.Views.AlertPage">
<popup:PopupPage.Animation>
<animations:ScaleAnimation
PositionIn="Bottom"
PositionOut="Bottom"
ScaleIn="1.2"
ScaleOut="0.8"
DurationIn="400"
DurationOut="300"
EasingIn="SinOut"
EasingOut="SinIn"
HasBackgroundAnimation="True" />
</popup:PopupPage.Animation>
<StackLayout Margin="30,0,30,0" VerticalOptions="Center" BackgroundColor="#121212">
<Grid VerticalOptions="Fill">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
<ColumnDefinition Width="50"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Text="Alert Title" TextColor="White" FontAttributes="Bold" Margin="20,20,20,0"></Label>
<Label Grid.ColumnSpan="3" TextColor="White" Grid.Row="1" VerticalOptions="StartAndExpand" Text="This is a Custom Popup made it Rg.Plugins.Popup to mimic the Default Android Alert" Margin="20,0"></Label>
<Label Margin="0,0,0,20" Grid.Column="2" FontAttributes="Bold" Grid.Row="2" VerticalOptions="End" Text="Yes" TextColor="White"></Label>
<Label Margin="0,0,0,20" Grid.Column="1" FontAttributes="Bold" Grid.Row="2" VerticalOptions="End" Text="No" TextColor="White"></Label>
</Grid>
</StackLayout>
</popup:PopupPage>
И это будет работать как обычная страница, вы можете добавить распознаватели жестов к меткам, привязать цвета так, чтобы цвет фона был динами c, все зависит от вас.
Предупреждение по умолчанию:
Окончательный результат: