EXI想在mywebview加載一個URL時,在選項菜單如何使用對象變量作爲全局/公共變量的Android
這裏的「物品1」最終用戶點擊是我的代碼:
package com.exemple.test;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebSettings;
import android.app.AlertDialog;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://m.google.com");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.item1:
//AlertDialog alertDialog = new AlertDialog.Builder(this).create();
//alertDialog.setTitle("Reset...");
//alertDialog.setMessage("Are you sure?");
//alertDialog.show();
myWebView.loadUrl("http://m.google.com");
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
謝謝!
問題標題和內容不匹配。你能澄清嗎? –