【问题标题】:Xamarin Forms where to change StatusBar For Android and IOSXamarin Forms 在哪里更改 Android 和 IOS 的 StatusBar
【发布时间】:2020-05-15 19:38:01
【问题描述】:

我正在使用 Xamarin.Forms 并希望在所有页面中导航以拥有 #84DCC6。它添加了,但我不想在导航页面的顶部有蓝色(这是 Android 项目中的默认值),我只想有一种颜色 #84DCC6。这是我在 App.xaml 中的代码


<Application.Resources>
        <ResourceDictionary>

        <Style TargetType="NavigationPage">
            <Setter Property="BarBackgroundColor" Value="#84DCC6" />
            <Setter Property="BarTextColor" Value="Black" />
        </Style>
        </ResourceDictionary>
    </Application.Resources>

我正在小米 A2 Lite 上测试我的应用程序。任何建议只是一种颜色#84DCC6

【问题讨论】:

    标签: xamarin.forms xamarin.android xamarin.ios


    【解决方案1】:

    你说的蓝色不是导航栏,是状态栏。

    安卓:

    您可以从位于您的 android 项目 Resource folder 下的 Styles.xml 文件更改其颜色:

    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#1eb6ed</item>
    

    iOS

    在您的应用委托类中使用以下代码

    var statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
                if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
                {
                    statusBar.BackgroundColor = UIColor.FromRGB(132, 220, 198);
                    statusBar.TintColor = UIColor.Black;
                }
    

    【讨论】:

    • 这个蓝色是在IOS中显示的吗?我现在没有IOS设备来测试?
    • 在iOS中你也可以设置状态栏的颜色,编辑我的答案。
    • 默认情况下,iOS中的UINavigationBar样式为Default,即字母为黑色,背景色为白色。
    • 请找到编辑后的答案,你可以有相同的RGB代码,并且在LoadApplication(new App())之前完成启动方法;你可以放这个。
    • 谢谢 MShah,这段代码正在运行,我标记为成功!
    猜你喜欢
    • 1970-01-01
    • 2018-11-29
    • 2023-03-16
    • 1970-01-01
    • 2019-01-17
    • 1970-01-01
    • 1970-01-01
    • 2017-05-05
    • 2016-09-24
    相关资源
    最近更新 更多