2013-07-30 34 views

回答

2

您需要使用VebView在應用程序中是這樣運行的瀏覽器:

佈局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
style="@style/my_style" > 

<WebView 
    android:id="@+id/myWebView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@id/help_tabbar" /> 

Java代碼

WebView webView = (WebView) findViewById(R.id.myWebView); 
    webView.getSettings().setJavaScriptEnabled(true); 

    final Activity activity = this; 
    webView.setWebViewClient(new WebViewClient() { 
     /** 
     * open page inside tabbar activity 
     */ 
     public void onReceivedError(WebView view, int errorCode, 
       String description, String failingUrl) { 
      Toast.makeText(activity, description, Toast.LENGTH_SHORT) 
        .show(); 
     } 
    }); 
    webView.loadUrl(getString(R.string.my_url)); 
} 

如果你想在外部瀏覽器中打開,你可以使用這個:

Intent intent = new Intent(Intent.ACTION_VIEW, 
       Uri.parse(getString(R.string.my_url))); 
     startActivity(intent); 

您的網址始終保持爲字符串,因爲它很容易修改。 希望這是有用的。 乾杯

+0

的WebView是一種選擇,第二一種可能是因爲我的代碼幾乎是相同的,不是它可以打開外部瀏覽器,讓活動留在堆棧中? – metinkale38

+1

這是困難的,因爲你或任何用戶可能有100個應用程序的同時運行。我的意見是讓網頁視圖,它是非常easyer任何用戶留在應用程序和搜索的網頁,然後把在BG的應用程序,打開的瀏覽器,關閉瀏覽器,恢復應用程序---當你看到有4個步驟,一個用戶應該只是一個簡單的網頁,insted的他可以使僅有1。 –

相關問題