我正在尝试在Xamarin for Android中获取窗口,但窗口返回空。我想要获得窗口的原因是,我可以应用一个标志来删除UI状态栏。
我已经寻找了一个与getWindow(java)等效的方法,但是没有找到。在本例中,我尝试使用this.Window:
var _winflag1 = WindowManagerFlags.Fullscreen;
this.Window.AddFlags(_winflag1); // window is always null这不起作用,所以我也尝试了实例化,但没有用:
var _winflag1 = WindowManagerFlags.Fullscreen;
var _window = this.Window; //_window is always null
_window.AddFlags(_winflag1);我想知道一种在Xamarin.Android中获取当前窗口的方法。
编辑:我忘记提到这是在MainActivity.cs内部。
https://github.com/hexag0d/BitChute_Mobile_Android_BottomNav/blob/FixLinkOverflow/MainActivity.cs
发布于 2019-08-19 08:30:03
问题是窗口变量必须在MainActivity.cs OnCreate中赋值。
public class MainActivity : FragmentActivity
{
//it is very important to instantiate with static
public static Window _window = null; // do this directly inside MainActivity
protected override void OnCreate(Bundle savedInstanceState)
{
//bunch of code here
_window = this.Window; //we can only assign Window inside
//OnCreate?? I tried to do it in another custom method
//but it would always return null
}
public void MyCustomWindowMethod()
{
//I was previously trying to assign window inside this method
//that doesn't work.
//this var hides the statusbar on android
var _winflag1 = WindowManagerFlags.Fullscreen;
//since we assigned window in OnCreate, now _window isn't null
_window.AddFlags(_winflag1);
}
}https://stackoverflow.com/questions/57549232
复制相似问题