Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status bar customisation does not work in android. #16240

Closed
Eugenenoble2005 opened this issue Jul 5, 2024 · 2 comments
Closed

Status bar customisation does not work in android. #16240

Eugenenoble2005 opened this issue Jul 5, 2024 · 2 comments

Comments

@Eugenenoble2005
Copy link

Describe the bug

Attempting to customise the status bar natively does not work at all in avalonia. All techniques mentioned in https://developer.android.com do not work.

[Activity(
    Label = "Fuzzycord.Android",
    Theme = "@style/MyTheme.NoActionBar",
    Icon = "@drawable/icon",
    MainLauncher = true,
    ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.UiMode)]
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.Red);
        base.OnCreate(savedInstanceState);
    }
    
    
}

It only works when AppCompatActivity is extended instead of AvaloniaMainActivity but then it wouldn't be an avalonia app anymore:

public class MainActivity : AppCompatActivity
{
    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.Red);
        base.OnCreate(savedInstanceState);
    }
    
    
}

To Reproduce

Create a new Avalonia xplat app and try to customise the android status bar whether through the style.xml, AndroidInset, AndroidSystemFlags, Window.SetSystemStatusBar color, EdgeToEdge, even Maui communityToolkit. No native apis will work if AvaloniaMainActivity is extended.

Expected behavior

Status bar should follow native styling

Avalonia version

11.0.9

OS

No response

Additional context

Android

@Eugenenoble2005
Copy link
Author

Found a fix. Override OnWindowFocusChanged instead of OnCreate:

 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);
    }

@maxkatz6
Copy link
Member

maxkatz6 commented Jul 8, 2024

Attempting to customise the status bar natively does not work at all in avalonia

You can use InsetsManager API for some customizations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants