0
package my.domain.app;
import android.app.Activity;
import android.os.Bundle;
import android.content.SharedPreferences;
import android.webkit.*;
public class MainActivity extends Activity {
private WebView webView;
private SharedPreferences sPref;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webapp);
}
void someMethod() {
WebView webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new MyWebViewClient());
String url;
if (sPref.contains("PREFS_ID"))
url = sPref.getString("PREFS_ID", "DEFAULT_VALUE");
else
url = "http://example.com";
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setAllowContentAccess(true);
webSettings.setSupportZoom(true);
webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
MyWebViewClient myWebViewClient = new MyWebViewClient();
webView.setWebViewClient(myWebViewClient);
webView.loadUrl(url);
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!url.equals("YOUR_FIRSTURL")) {
sPref.edit().putString(url, "PREFS_ID").commit();
}
return true;
}
}
}
我想,他打開http://example.com但如果我去http://example.com/page2,當我重新打開網頁視圖他打開http://example.com/page2 我現在有用更多的細節更新了代碼。
如何 – Anoniem
@Anoniem把這個在我的劇本與websettings更新我的例子 –
我更新了一些更詳細的代碼。我現在沒有錯誤了,但是當我開始活動時,我得到了一個白色屏幕。 – Anoniem