我已经编写了一个基本应用程序,用于测试沉浸式模式或全屏模式(仅隐藏状态栏)在Webview应用程序上的工作方式。
这是我的main_activity。请注意,就我所知,这只是一个遵循api指南的测试应用程序。
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView mWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// Force links and redirects to open in the WebView instead of in a browser
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl("http://baidu.com"); //just a test website, doesn't matter really. Just need a text box low enough on screen.
setupFullscreenMode();
}
private void setupFullscreenMode() {
View decorView = setFullscreen();
decorView
.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
setFullscreen();
}
});
}
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
setFullscreen();
}
}
private View setFullscreen() {
View decorView = getWindow().getDecorView();
//FLAG ORDERING MAKES A DIFFRENCE
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE // without the other layout flags, this results in glitched out status and navagation spaces
//unsurprisingly everything (pre-selected scenario etc) works fine with this flag, but it's not true fullscreen
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // This also breaks the pre-seclected scenario
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // This breaks the pre-selected scenario
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION //2
| View.SYSTEM_UI_FLAG_FULLSCREEN //1
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);//3 with 1,2,3 there's some glitching still going on(ghost statusbar)
return decorView;
}
简而言之,这是我的错误 -
预期行为将是调整应用程序的大小,因为当我尝试在没有全屏或沉浸式模式的情况下执行此操作时会发生这种情况。
这里发生了什么导致失败? 在我的实际应用程序中,这是非常令人沮丧的片状。无论是否预先选择了文本框,它都可能调整或不调整应用程序的大小。
目前,我只对了解此测试应用的行为感兴趣。