Android web button forward

I want to know how to disable and enable the menu button forward, as in a separate android browser. I am writing an application in which I show 3 web views, and I want to enable the basic functions of my own browser options for Android. Everything is working fine at the moment violate the functionality. The only thing there is: "forward'menu item is always on. I mentioned conditoin too if canGoFwd then goFwd. The fact is that I defined the menu items separately and wrote the direct function separately, the problem is the dynamically changing states for the forward button

+3
source share
1 answer
private WebView webView;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);

    webView = (WebView) findViewById(R.id.webView1);
    webView.getSettings().setJavaScriptEnabled(true);
    final Button previousButton =(Button) findViewById(R.id.previousButton);

    previousButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

               if(webView.canGoBack()){
                   webView.goBack();
               }
        }
    });
    final Button forwardButton =(Button) findViewById(R.id.forwardButton);

    forwardButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

               if(webView.canGoForward()){
                   webView.goForward();
               }
        }
    });
    webView.setWebViewClient( new WebViewClient() {



        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished( WebView view, String url ) {

            super.onPageFinished(webView, url );

            previousButton.setEnabled(view.canGoBack());
            forwardButton.setEnabled(view.canGoForward());

        }

        @Override
        public void onReceivedError( WebView view, int errorCode, String description, String failingUrl ) {

            super.onReceivedError( webView, errorCode, description, failingUrl );
            Toast.makeText( WebViewActivity.this, description, Toast.LENGTH_LONG );
        }
    } );
    webView.loadUrl("");

Webview.xml file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <WebView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <Button
        android:id="@+id/previousButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:enabled="false" 
        android:text="previous"/>

    <Button
        android:id="@+id/forwardButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/previousButton"
        android:text="forward"
        android:enabled="false" />
</RelativeLayout>
+4
source

Source: https://habr.com/ru/post/1787503/


All Articles