2017-08-04 55 views

回答

0

我不知道你需要什麼澄清,因爲你已經回答了你自己的問題(不管你意識到與否)

public class MyActivity extends Activity { 

    WebView webView; 

    // You can define as many of these as you like 
    String urlString1 = "www.google.com"; 
    String urlString2 = "www.facebook.com"; 

    ... 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     ... 
     webView = (WebView) findViewById(R.id.my_web_view_id): 
     ... 
     webView.loadUrl(new Url(urlString)); 

    } 

} 

如果你想使用共享偏好:

// initialize prefs 
SharedPreferences sharedPreferences = getSharedPreferences("some_string_identifier" , Context.MODE_PRIVATE); 
// get url 
urlString1 = sharedPreferences.getString("url", null); 

// save url 
Editor editor = sharedPreferences.edit();  
editor.putString("url", urlString1); 
editor.commit(); 
+0

Thnaks,我的意思是字符串加載url文本形式(共享首選項保存) – user3515102

+0

我編輯我的答案 – anomeric