2011-03-30 59 views
2

好的,所以我已經完成了我的應用程序,並且我正在對其進行微小的調整,並且有一點是我希望我的web鏈接在webview中啓動,而不是股票瀏覽器...我試過這麼多事情,我不斷收到錯誤和Eclipse保持啓動調試角度,我被困..需要幫助從股票android瀏覽器更改爲webview

// XXXX.edu Button 
     Button XXXX_Button = (Button)findViewById(R.id.XXXX_Button); 
     XXXXXX_Button.setOnClickListener(new View.OnClickListener() 
     { 
     public void onClick(View v) 
     { 
      Uri uri = Uri.parse("http://www.XXXXXX.edu/"); 
      startActivity(new Intent(Intent.ACTION_VIEW, uri)); 
     } 
     }); 

回答

0

您需要延長WebViewClient,並在啓動網址那。

public class WebActivity extends Activity 
{ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     webview = (WebView) findViewById(R.id.wv); 
     webview.setWebViewClient(new WebC()); 
     webview.loadUrl(baseUrl); 
    } 

    public class WebC extends WebViewClient 
    { 
     @Override 
     public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) 
     { 
      super.onReceivedError(view, errorCode, description, failingUrl); 
     } 

     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) 
     { 
    ... etc. 

而在你的佈局XML,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 

    <WebView 
     android:id="@+id/wv" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"/> 
</LinearLayout> 
+0

我不明白如何在我的Java使用部分文件,我在我的XML中的一部分,但Java文件是搞亂了我,我是否需要爲每個鏈接創建一個字符串,然後放入@ string/website1,而字符串網站1是我的網站鏈接。就像我說的這對我來說是全新的,我剛剛開始開發android應用程序,所以我非常感謝所有幫助。 – peter 2011-04-04 16:05:24

+0

在上面的代碼中,只需用您的硬編碼路徑替換'baseUrl'即可。一旦你得到它的工作,你可以看看[字符串資源](http://developer.android.com/guide/topics/resources/string-resource.html) – rajath 2011-04-05 05:26:27