2016-06-07 67 views
1

好日子所有,如何獲得在Android Studio中使用的WebView

我做一個簡單的應用程序(實踐的目的)使用在Android Studio中一的WebView所有URL。我希望我的應用能夠烘烤我輸入/瀏覽的所有網址。例如,當我打開Facebook時,它會將其網址烘烤,當我登錄到我的帳戶時,它會再次爲我的Facebook帳戶敬酒,聽起來就像那樣。這是我的代碼。我是新東西的東西,任何建議或幫助將不勝感激。非常感謝。

XML佈局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       tools:context="com.example.nevigrof.ymuc.Back_order"> 

     <WebView 

        android:layout_weight="1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:focusable="true" 
        android:id="@+id/webview1"/> 
</RelativeLayout> 

的Java代碼

 @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      view.loadUrl(url); 
      return true; 
     } 
    } 

    WebView webview; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_survey_form); 

     webview = (WebView) findViewById(R.id.webview1); 
     webview.setWebViewClient(new MyWebViewClient()); 
     openURL(); 
    } 

    private void openURL() { 

     webview.requestFocus(View.FOCUS_DOWN | View.FOCUS_UP); 
     webview.loadUrl("http:/https://www.facebook.com/"); 
     webview.getSettings().setJavaScriptEnabled(true); 


     String webUrl = webview.getUrl(); 
     Toast.makeText(Back_order.this, webUrl, Toast.LENGTH_LONG).show(); 
    } 
} 
+0

有一個在webview.loadUrl() – jomartigcal

回答

0

我想MyWebViewClient繼承自WebViewClient;您應該在MyPageViewClient類中的onPageStarted和/或onPageFinished上覆蓋 。

@Override 
public void onPageFinished(WebView view, String url) { 
    super.onPageFinished(view, url); 
    // Toast 
} 

,看一下:

WebViewClient onPageFinished Android doc

Load an HTML document Android training

+0

爵士在URL中的錯字這是真棒,它的工作我想要的方式謝謝你的時間和精力幫助我。我已經點擊向上箭頭進行投票,但它只會在我有15個代表時纔會出現, –

相關問題