英文:
.Net MAUI Android App: Change Navigation and Status Bar colors at Splash screen moment
问题
我正在尝试更改我的.Net MAUI Android应用程序中的导航栏和状态栏背景颜色。
我找到了在应用程序初始化和加载后执行此操作的方法(状态栏:使用MauiCommunityToolkit StatusBarBehavior StatusBarColor功能。导航栏:使用Window.SetNavigationBarColor)。
但是,我尚未找到在应用程序启动并显示启动屏幕时执行此操作的方法。我需要为状态栏和导航栏都设置黑色背景颜色,但当应用程序启动时,导航栏是白色的,状态栏是紫色的(默认的.Net MAUI颜色)。我附上了应用程序启动时的外观图像。
我尝试更改Resources/colors.xml中的主要颜色,但没有成功。
我的应用程序是一个MAUI单一项目模板(Android和iOS)。
感谢您提前查看此问题。
更新:我已经成功更改了状态栏的颜色,只需更改Platforms/Android/Resources/colors.xml中的colorPrimaryDark值
[]
但我仍在寻找如何更改导航栏颜色。
[]
英文:
I'm trying to change Navigation Bar and Status Bar background color in my .Net MAUI Android App.
I found how to do that when the app has initialized an loaded (Status Bar: Using MauiCommunityToolkit StatusBarBehavior StatusBarColor feature. Navigation Bar: Using Window.SetNavigationBarColor).
But I have not found how to do that when the app starts and shows the Splash Screen. I need black background color for both, Status and Navigation bar but when the App starts, NavBar is white and Status Bar is Purple (default .Net MAUI color). I attached an image of how it looks when starts.
I tried changing the Primary Color in the Resources/colors.xml, and it didn't work.
My App is a MAUI Single project template (Android and iOS).
Thanks in advance for taking a look at this issue.
UPDATE: I was able to change just Status Bar, changing defautl colorPrimaryDark value in Platforms/Android/Resources/colors.xml
答案1
得分: 5
你可以创建一个新的.xml文件,然后将样式放入其中,或者直接将样式添加到colors.xml中:
<resources>
<color name="colorPrimary">#512BD4</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
<style name="SplashTheme" parent="@style/Maui.SplashTheme">
<item name="android:statusBarColor">@android:color/black</item>
<item name="android:navigationBarColor">@android:color/black</item>
</style>
</resources>
在MainActivity.cs文件(Platforms/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
它可以很好地实现您的需求。
英文:
You can create a new .xml file and then put the style in or add the style to colors.xml directly:
<resources>
<color name="colorPrimary">#512BD4</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
<style name="SplashTheme" parent="@style/Maui.SplashTheme">
<item name="android:statusBarColor">@android:color/black</item>
<item name="android:navigationBarColor">@android:color/black</item>
</style>
</resources>
In the MainActivity.cs file (Platforms/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
It works well and can achieve your need.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论