晚上好,
我在Android studio中开发了一个打开网页的应用程序。我希望全屏显示(即屏幕顶部没有通知栏)。看看论坛,我补充说:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//... some additional code here ...
View decorView = setFullscreen();
decorView
.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
setFullscreen();
}
});
webView.loadUrl(myUrl);
}
private View setFullscreen() {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
return decorView;
}
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
setFullscreen();
}
}
除非我点击我加载的页面的其中一个链接,否则一切都会完美无缺:当加载另一个页面时,顶部通知栏会再次显示。
任何人都知道我错过了什么?
感谢您的帮助和祝福, 劳伦
答案 0 :(得分:0)
可以在您的活动类中使用此代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
它会使您的活动全屏无状态栏。