gpt4 book ai didi

android - 需要帮助更新 WebView 的后退/前进按钮

转载 作者:行者123 更新时间:2023-11-29 14:56:29 25 4
gpt4 key购买 nike

我有一个 WebView 和一个位于底部的布局,其中包含后退和上一个按钮。我正在寻找一种方法来根据 WebView 的历史记录准确设置这些按钮的启用状态。我在 WebViewClient 中尝试了 doUpdateVisitedHistory 方法,但只有在加载新 URL 时才会更新...不适用于链接只是向下滚动当前页面的情况,这显然仍然保留在 WebView 的历史记录中。如何捕获 WebView 历史记录的所有添加?

最佳答案

解决方法如下:

    webView.setWebViewClient( new WebViewClient() {

@Override
public void onPageStarted( WebView view, String url, Bitmap favicon ) {

super.onPageStarted( webView, url, favicon );
progressBar.setVisibility( View.VISIBLE );
}

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

super.onPageFinished( webView, url );
progressBar.setVisibility( View.INVISIBLE );

previousButton.setEnabled( view.canGoBack() );
nextButton.setEnabled( view.canGoForward() );
}

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

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

关于android - 需要帮助更新 WebView 的后退/前进按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5477000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com