android.webkit.WebView.goBackOrForward()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(1.7k)|赞(0)|评价(0)|浏览(464)

本文整理了Java中android.webkit.WebView.goBackOrForward()方法的一些代码示例,展示了WebView.goBackOrForward()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebView.goBackOrForward()方法的具体详情如下:
包路径:android.webkit.WebView
类名称:WebView
方法名:goBackOrForward

WebView.goBackOrForward介绍

暂无

代码示例

代码示例来源:origin: luili16/UIMocker

@Override
public void goBackOrForward(int steps) {
  mWebView.goBackOrForward(steps);
}

代码示例来源:origin: stackoverflow.com

public class BackButtonListener implements View.OnKeyListener {

  @Override
  public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
      WebView webView = (WebView) v;

      switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
          WebBackForwardList backstack = webView.copyBackForwardList();
          int currentIndex = backstack.getCurrentIndex();
          int i = -1;
          while (webView.canGoBackOrForward(i)) {
            if (!backstack.getItemAtIndex(currentIndex + i).getUrl().equals("about:blank")) {
              webView.goBackOrForward(i);
              return true;
            }
            i--;
          }
          webView.goBack();
          return true;
      }
    }
    return false;
  }
}

代码示例来源:origin: vbier/habpanelviewer

@Override
public void goBackOrForward(int steps) {
  Log.d(TAG, "goBackOrForward: steps=" + steps);
  int increment = steps < 0 ? -1 : 1;
  WebBackForwardList list = copyBackForwardList();
  int count = 0;
  int intCount = 0;
  int startIdx = list.getCurrentIndex();
  for (int i = startIdx + increment; i < list.getSize() && i >= 0; i += increment) {
    intCount += increment;
    WebHistoryItem item = list.getItemAtIndex(i);
    Log.d(TAG, "goBackOrForward: item=" + item.getOriginalUrl());
    if (!item.getOriginalUrl().startsWith("data:")) {
      count += increment;
      if (count == steps) {
        Log.d(TAG, "goBackOrForward: intCount=" + intCount + ", item=" + item.getOriginalUrl());
        super.goBackOrForward(intCount);
        return;
      }
    }
  }
}

相关文章

WebView类方法