如何更改 .Net MAUI Android 中的警报样式?

问题描述 投票:0回答:1

我正在将应用程序从 Xamarin 移植到 .Net MAUI,在 Xamarin 中我在 Android 中使用浅色主题,因此警报具有白色背景,但在 MAUI 中警报具有灰色背景。

如何将警报背景更改为白色背景?

enter image description here

maui alert background-color android-theme light
1个回答
0
投票

为了解决这个问题,我首先创建了一个包含以下内容的“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 目录中:

enter image description here

然后我将构建操作设置为“AndroidResource”

enter image description here

我编辑了文件“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
    {
    }
}

完成!,成功了

© www.soinside.com 2019 - 2024. All rights reserved.