你如何使ContentPage全屏?

时间:2014-12-09 19:13:02

标签: xamarin.forms

在Xamarin.Forms 1.3+中,如何制作ContentPage全屏? ContentPage的最基本的例子是在创建Xamarin.Forms Portable项目时提供的例子。

public App (){
    // The root page of your application
    MainPage = new ContentPage {
        Content = new StackLayout {
            VerticalOptions = LayoutOptions.Center,
            Children = {
                new Label {
                    XAlign = TextAlignment.Center,
                    Text = "Welcome to Xamarin Forms!"
                }
            }
        }
    };
}

更多信息(Android):https://developer.android.com/training/system-ui/immersive.html

3 个答案:

答案 0 :(得分:1)

您的ContentPage是全屏的。只有ContentPage中的内容不会填满整个屏幕。
你可以尝试这样的事情:

HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,

答案 1 :(得分:0)

您的内容页面是全屏的。您可以通过更改内容页面的背景颜色进行检查。请尝试以下代码

BackgroundColor = Color.White

答案 2 :(得分:0)

制作全屏的步骤1是隐藏导航栏。这可以在导航到视图时进行控制。

FullScreenVideoPlayerPage fullScreenVideoPage = new FullScreenVideoPlayerPage();
NavigationPage.SetHasNavigationBar(fullScreenVideoPage, false);
await Navigation.PushAsync(fullScreenVideoPage);

使用await时,请记住在Method Signature中使用async关键字。

private async void FullScreenVideoPlayerPage_Clicked(object sender, EventArgs e)

第2步是隐藏Android状态栏。但似乎这不是Android的标准。我没有完全成功隐藏这个酒吧。但我可以通过以下方式隐藏状态图标:

using Android.App;
using Android.Views;

//......

// Call this method from the constructor after InitializeComponent ();
public void HideStatusBar()
{
var activity = (Activity)Forms.Context;
var window = activity.Window;
var attrs = window.Attributes;
attrs.Flags |= Android.Views.WindowManagerFlags.Fullscreen;
window.Attributes = attrs;

window.ClearFlags(WindowManagerFlags.ForceNotFullscreen);
window.AddFlags(WindowManagerFlags.Fullscreen);

var decorView = window.DecorView;

var uiOptions =
    (int)Android.Views.SystemUiFlags.LayoutStable |
    (int)Android.Views.SystemUiFlags.LayoutHideNavigation |
    (int)Android.Views.SystemUiFlags.LayoutFullscreen |
    (int)Android.Views.SystemUiFlags.HideNavigation |
    (int)Android.Views.SystemUiFlags.Fullscreen |
    (int)Android.Views.SystemUiFlags.Immersive;

decorView.SystemUiVisibility = (Android.Views.StatusBarVisibility)uiOptions;

window.DecorView.SystemUiVisibility = StatusBarVisibility.Hidden;
}