android - DialogFragment with WebView - Handling back button? -


It should be that simple, but I can not find a working solution ...

I have a DialogFragment that has a linear layout that includes a WebView. When the user navigates into the webview, I want to be able to go back using the back button. When he / she reaches the start page (i.e. can not go back), the back button dialog should be closed. I tried setCancelable (wrong) and DialogFragments was reversed with an OnKeyListener on the root view (one that was incremented), but it never seems to call back the button. I do not want to include onBackPressed of the activity (it should be controlled by DialogFragment if possible).

So far the solution I found is to install WebView's OnKeyListener like this:

  @Override Public View onCreateView (LayoutInflater Inflator, ViewGroup Container, Bundle savedInstanceState) {View V = inflater.inflate (R.layout.dialog_fragment_layout, Container, Incorrect) WebView = (WebView) V. FindViewById (R.id.webView) ); WebView.setOnKeyListener; return v;} OnKeyListener keyListener = new OnKeyListener () {@Override Public Boolean onKey (see V, Integer Keycode, KeyEve NT Event) {if (keycode == KeyEvent.KEYCODE_BACK & amp; ; Event.getAction () == KeyEvent.ACTION_DOWN) {if (webView.canGoBack ()) {webView.goBack (); Back true; } } return false; }};    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -