我正在尝试更改使用 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 状态栏?
找到修复方法。重写 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);
}