I Am trying to make a full screen Webview app and when ever a user searches something on a web page the keyboard pops up(obviously) and the navbar and the status bar show up but when the user closes the keyboard, the navigation bar and the status bar don't hide as they normally should, instead they just stay there until the user slides the status bar down and swipes up again.
How Do i fix This? I've searched the internet for the problem and apparently many newbies like me face the same issues. It would be helpful if you provide me the solution.
here is my code. (mainactivity.java)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// find the WebView by name in the main.xml of step 2
browser=(WebView)findViewById(R.id.webview);
// Enable javascript
browser.getSettings().setJavaScriptEnabled(true);
// Set WebView client
browser.setWebChromeClient(new WebChromeClient());
browser.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// open in Webview
if (url.contains("example.com") ){
// Can be clever about it like so where myshost is defined in your strings file
// if (Uri.parse(url).getHost().equals(getString(R.string.myhost)))
return false;
}
// open rest of URLS in default browser
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
});
// Load the webpage
browser.loadUrl("http://example.com/");
}
//back button
public void onBackPressed() {
if (browser.canGoBack()) {
browser.goBack();
} else {
super.onBackPressed();
}
}
// nav bar and status bar hide..... should figure out glitch with keyboard
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
}
}
}