Xamarin.Android: Скрыть StatusBar и уведомления в полноэкранном режиме - PullRequest
0 голосов
/ 27 августа 2018

Я пытаюсь скрыть строку состояния и уведомления в полноэкранном режиме.Пользователь не должен иметь возможность тянуть / прокручивать строку состояния / уведомлений в Xamarin android.

В нативном android работает нормально со свойством ниже (версия для Android 8.0).

View decorView = getWindow().getDecorView(); 
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

getWindow().setFlags(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);

Эквивалент TYPE_APPLICATION_OVERLAY в xamarin не удалось получить.

Любое решение для Xamarin.Android?

Я пробовал ниже свойства для xamarin:

View decorView = Window.DecorView;
    var uiOptions = (int)decorView.SystemUiVisibility;
    var newUiOptions = (int)uiOptions;      
    newUiOptions |= (int)SystemUiFlags.HideNavigation;
    newUiOptions |= (int)SystemUiFlags.LayoutHideNavigation;
    newUiOptions |= (int)SystemUiFlags.LayoutFullscreen;
    newUiOptions |= (int)SystemUiFlags.Fullscreen;
    newUiOptions |= (int)SystemUiFlags.ImmersiveSticky; 
    decorView.SystemUiVisibility = (StatusBarVisibility)newUiOptions;

    Window.AddFlags(WindowManagerFlags.TranslucentNavigation);
    Window.AddFlags(WindowManagerFlags.TranslucentStatus);
    Window.ClearFlags(WindowManagerFlags.ForceNotFullscreen);

Ответы [ 2 ]

0 голосов
/ 27 августа 2018

Этот код используется для создания представления для наложения области statusBar, но не уверен, работает ли он на Oreo.

Требуется разрешение SYSTEM_ALERT_WINDOW.

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.Main);

        WindowManagerLayoutParams localLayoutParams = new WindowManagerLayoutParams();

        localLayoutParams.Type = WindowManagerTypes.SystemError;
        localLayoutParams.Gravity = GravityFlags.Top;
        localLayoutParams.Flags = WindowManagerFlags.NotFocusable | 
            WindowManagerFlags.NotTouchModal | WindowManagerFlags.LayoutInScreen;
        localLayoutParams.Width = WindowManagerLayoutParams.MatchParent;
        localLayoutParams.Height = (int)(50 * Resources.DisplayMetrics.ScaledDensity);
        localLayoutParams.Format = Format.Transparent;

        IWindowManager manager = ApplicationContext.GetSystemService(Context.WindowService).JavaCast<IWindowManager>();
        customViewGroup view = new customViewGroup(this);

        manager.AddView(view, localLayoutParams);
    }
    public class customViewGroup : ViewGroup
    {
        public customViewGroup(Context context) : base(context)
        {
        }
        public override bool OnTouchEvent(MotionEvent ev)
        {
            return true;
        }
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            // throw new NotImplementedException();
        }
    }

Надеюсь, это поможет.

исходный код Java: https://stackoverflow.com/a/25397029/3814729

0 голосов
/ 27 августа 2018

Изменение флагов окна в OnCreate на полноэкранный режим должно помочь,

 this.Window.AddFlags(WindowManagerFlags.Fullscreen); //to show
 this.Window.ClearFlags(WindowManagerFlags.Fullscreen); //to hide

Возврат, если он не работает.

Обновление:

        if ((int)Android.OS.Build.VERSION.SdkInt >= 19)
        {
            var decorView = this.Window.DecorView;
            decorView.SystemUiVisibility = StatusBarVisibility.Hidden;// (StatusBarVisibility)newUiOptions;
        }
        else
        {
            var attrs = this.Window.Attributes;
            attrs.Flags |= WindowManagerFlags.Fullscreen;
            this.Window.Attributes = attrs;
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...