We sometimes implement webview in fragment.
But 'back key' not working in webview of fragment.
Because webview is not activity but fragment.
So we add back button.
But possible to using back key in webview of fragment.
Add this code to MainActivity.java
- @Override
- public void onBackPressed() {
- if (webfragment.webview.canGoBack()) {
- try{
- webfragment.webview.goBack(); //only webview back-key code
- //back-key code of another fragment
- }
- }else {
- // back-key code of another fragment
- }
Add onBackPressed method in MainActivity.java
line 3 : Method canGoBack() means possible to go back in webview.
line 5 : Method goBack() means go back in webview.
No comments:
Post a Comment