如何更改 xamarin.android 中默认显示警报的背景颜色? [英] How to change Background Color of Default Display alert in xamarin.android?
本文介绍了如何更改 xamarin.android 中默认显示警报的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更改显示警报的默认背景颜色,我在不同的网站上尝试了很多问题有人可以帮我吗?
I want to change default background color of display alert,I have tried many questions in different sites Can anyone help me ?
推荐答案
如果不想使用Rg.Plugins.Popup
,在android中,可以用来实现AlertDialog
和自定义样式.您可以通过 DependencyService
调用它.
If you do not want to use Rg.Plugins.Popup
, In the android, you can achieve it with a AlertDialog
and custom style.You can call it by DependencyService
.
[assembly: Dependency(typeof(DeviceOpenAlertService))]
namespace App2.Droid
{
class DeviceOpenAlertService : IDeviceOpenAlertService
{
public void Open()
{
var alert = new AlertDialog
.Builder(CrossCurrentActivity.Current.Activity, Resource.Style.MyDialogStyle)
.SetTitle("Alert Title")
.SetMessage("Do you want to close this application")
.SetPositiveButton("Yes", new myButtonClicklistener())
.SetNegativeButton("No", new myButtonClicklistener())
.Create();
alert.Show();
}
}
}
将以下样式添加到 styles.xml
<style name="MyDialogStyle" parent="android:Theme.Material.Light.Dialog.NoActionBar">
<!--Dialog Background Color-->
<item name="android:colorBackground">#FF0000</item>
</style>
<style name="MyButtonsStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<!-- text color for the button -->
<item name="android:textColor">#00ff00</item>
</style>
在 PCL 中调用它.
Call it in the PCL.
DependencyService.Get<IDeviceOpenAlertService>().Open();
这里正在运行 GIF.
Here is running GIF.
这篇关于如何更改 xamarin.android 中默认显示警报的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文