我正在将应用程序从 Xamarin 移植到 .Net MAUI,在 Xamarin 中我在 Android 中使用浅色主题,因此警报具有白色背景,但在 MAUI 中警报具有灰色背景。
如何将警报背景更改为白色背景?
为了解决这个问题,我首先创建了一个包含以下内容的“styles.xml”:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
然后我将该文件添加到目录 Platforms/Android/Resources/values 目录中:
然后我将构建操作设置为“AndroidResource”
我编辑了文件“MainActivity.cs”来设置主题“AppTheme”
using Android.App;
using Android.Content.PM;
using Android.OS;
namespace MyAppMaui
{
[Activity(Theme = "@style/AppTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
}
完成!,成功了