我试图在我的WebView应用程序中取回按钮功能,但是onBackPressed()函数正在给出错误'无法解析符号webView'
这是我的代码:
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdView mAdView;
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
WebView webView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
// To keep browser in width of phone
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
// Sets default text size
webSettings.setTextZoom(175);
MyWebViewClient webViewClient = new MyWebViewClient();
webView.setWebViewClient(webViewClient);
webView.loadUrl("http://www.google.com");
}
@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}
答案 0 :(得分:2)
你可以在onBackPressed中执行此操作:
total_amount = models.DecimalField(max_digits=10,decimal_places=2,blank = True,null = True,default = Decimal('0.00'))
编辑: 你可以这样做(带字段):
@Override
public void onBackPressed() {
WebView webView = (WebView) findViewById(R.id.webview);
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}