如何在.net android应用程序中设置状态栏的颜色?

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

我正在尝试更改使用 avalonia 作为 UI 的 Android 应用程序的颜色。

这是我的

MainActivity

public class MainActivity : AvaloniaMainActivity<App>
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        View decorView = Window.DecorView;
        var uiOptions = decorView.WindowSystemUiVisibility;
        var newuioptions = uiOptions;
        newuioptions |=  SystemUiFlags.LayoutStable |  SystemUiFlags.LayoutFullscreen;
        decorView.SystemUiFlags = newuioptions;
        Window.SetStatusBarColor(Color.Orange);
        base.OnCreate(savedInstanceState);
    }

    protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
    {
        return base.CustomizeAppBuilder(builder)
            .WithInterFont()
            .UseReactiveUI();
    }
}

无论我做什么,状态栏都保持不变。我缺少什么以及如何更改 Android 状态栏?

c# android .net xamarin avalonia
1个回答
0
投票

找到修复方法。重写 OnWindowFocusChanged 而不是 OnCreate。 avalonia 创建的视图干扰了它

 public override void OnWindowFocusChanged(bool hasFocus)
    {  
        View decorView = Window.DecorView;
        var uiOptions = decorView.WindowSystemUiVisibility;
        var newuioptions = uiOptions;
        newuioptions |=  SystemUiFlags.LayoutStable |  SystemUiFlags.LayoutFullscreen;
        decorView.SystemUiFlags = newuioptions;
        Window.SetStatusBarColor(Color.Transparent);
        base.OnWindowFocusChanged(hasFocus);
    }

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