.NET MAUI修改Android工具栏

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

这是我第一次尝试 MAUI 应用程序,我还没有使用 Xamarin 构建任何应用程序。
在发布本文时,我的项目仍在使用 .NET 7,并且我专注于开发 Windows 和 Android 平台。我已经能够通过几种方法修改默认的 Android 工具栏

NavigationPage.SetHasBackButton(this, false);
NavigationPage.SetTitleView(this, NavGrid);

NavGrid 取代了默认工具栏,但发现 Android 工具栏包装器上设置了默认填充。

我已经从 this S.O. 找到了解决方案。 post(其中包括显示我遇到的问题的图像),但我不确定如何将其转换为 MAUI 代码。我希望有人能指出我正确的方向。

android .net maui toolbar
1个回答
0
投票

您可以创建一个新的 .xml 文件并在其中添加样式。

<style name="SplashTheme" parent="Widget.AppCompat.ActionBar">
    <item name="contentInsetStart">0dp</item>
    <item name="contentInsetEnd">0dp</item>
</style>

然后,您可以使用MainActivity.cs文件中的.xml文件(平台/Android):

[Activity(
    //Theme = "@style/Maui.SplashTheme",
    Theme = "@style/SplashTheme",
    MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
public class MainActivity : MauiAppCompatActivity
© www.soinside.com 2019 - 2024. All rights reserved.