我面对的是意想不到的令牌' if-else条件中的错误使用&&amp ;.没有任何其他错误可以看到。
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class Support extends AppCompatActivity {
WebView webViewsupport;
ProgressBar progressBar;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_support);
webViewsupport = (WebView) findViewById(R.id.webView);
progressBar = (ProgressBar)findViewById(R.id.progressBar2);
webViewsupport.setWebViewClient(new myWebClient());
webViewsupport.getSettings().setJavaScriptEnabled(true);
webViewsupport.loadUrl("https://example.com");
}
public class myWebClient extends WebViewClient{
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return super.shouldOverrideUrlLoading(view, url);
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_BACK) && webViewsupport.canGoBack(){
webViewsupport.goBack();
}
return super.onKeyDown(keyCode, event);
}
}
我无法理解为什么它在这里使用&&显示意外令牌。
input$Product
答案 0 :(得分:0)
你的代码中有一个拼写错误(你的结尾括号放在错误的位置):
应该是:
if (keyCode == KeyEvent.KEYCODE_BACK) && webViewsupport.canGoBack(){
webViewsupport.goBack();
}
因此而投票结束。
答案 1 :(得分:-1)
您需要在()中添加整个条件:
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode==KeyEvent.KEYCODE_BACK && webViewsupport.canGoBack()){
webViewsupport.goBack();
}
return super.onKeyDown(keyCode, event);
}