在Xamarin表单中是否有任何方法可以更改对话框的背景色?
下面是我的对话框的黑色主题 有人知道在Xamarin Forms应用程序中更改颜色的方法吗?这样对话框就可以在深色背景下显示白色文本 有人知道问题出在哪里吗?选项1 您可以通过使用DependencyService在特定平台中更改它 以形式 创建接口在Xamarin表单中是否有任何方法可以更改对话框的背景色?,xamarin,xamarin.forms,Xamarin,Xamarin.forms,下面是我的对话框的黑色主题 有人知道在Xamarin Forms应用程序中更改颜色的方法吗?这样对话框就可以在深色背景下显示白色文本 有人知道问题出在哪里吗?选项1 您可以通过使用DependencyService在特定平台中更改它 以形式 创建接口 using Xamarin.Forms; namespace xxx { public interface IPopUp { void Popup(string title, string message,Color
using Xamarin.Forms;
namespace xxx
{
public interface IPopUp
{
void Popup(string title, string message,Color titleColor,Color messageColor, EventHandler handler);
}
}
在iOS中
在Android中
主要活动
public static MainActivity Intance;
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Intance = this;
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
并以表格形式称之为
DependencyService.Get<IPopUp>().Popup("Title","xxxxxxxxxxxx",Color.Red,Color.Blue,(sen,args)=> {
// handle the logic when clikc the OK button
});
选择2
您可以使用该插件,它允许以弹出窗口的形式打开Xamarin.Forms页面,可以在iOS、Android和UWP之间共享。您可以根据需要对其进行自定义。您好,到目前为止,我刚刚试用了您的iOS解决方案,但iOS自定义渲染器中出现了空引用异常。我把细节放在问题里。你知道可能出了什么问题吗?请注意,我使用的是XamarinShell和最新的4.4版本。提前谢谢。查看屏幕截图,你可以分享你的示例,这样我就可以在我这边测试它了。你好,卢卡斯,我在DependencyService中使用了你的代码。很抱歉,我不清楚你的代码是否出现了问题。它在我这方面运行良好,因此你可以分享你的示例吗?嗨,Lucas,我的示例是一个包含200多个文件和一个数据库的应用程序。我需要一些时间来制作一个小样品。此时它似乎失败了:SharedApplication.Delegate.GetWindow,因此我不确定我显示的调试输出是否有帮助。如果在那一点上进行调试,那么您的代码中与我的代码相同的地方是什么样的?
using Xamarin.Forms;
using xxx;
using xxx.Droid;
using Android;
using System;
using Xamarin.Forms.Platform.Android;
using Android.Support.V7.App;
using Android.Text;
[assembly: Dependency(typeof(PopupImplemention))]
namespace xxx.Droid
{
public class PopupImplemention : IPopUp
{
public void Popup(string title, string message, Color titleColor, Color messageColor, EventHandler handler)
{
// because html.string could not support format string , so you need to set the color directly in the string with a static value
Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(MainActivity.Intance);
alert.SetTitle(Html.FromHtml(string.Format("<font color='#ff0000'>{0}</font>" ,title),FromHtmlOptions.ModeLegacy));
alert.SetMessage(Html.FromHtml(string.Format("<font color='#00ff00'>{0}</font>", message), FromHtmlOptions.ModeLegacy));
alert.SetPositiveButton("OK", (senderAlert, args) =>
{
handler?.Invoke(senderAlert, args);
});
alert.SetNegativeButton("Cancel", (senderAlert, args) =>
{
});
Android.Support.V7.App.AlertDialog dialog = alert.Create();
dialog.Show();
}
}
}
DependencyService.Get<IPopUp>().Popup("Title","xxxxxxxxxxxx",Color.Red,Color.Blue,(sen,args)=> {
// handle the logic when clikc the OK button
});