2016-08-15 3 views
1

をロードしていない私は私のフラグメントのレイアウトにWebViewを入れている:WebViewのページ

<FrameLayout 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.deped.k12.GradeSheet" 
    android:background="#fafafa"> 

    <!-- TODO: Update blank fragment layout --> 

    <WebView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/webView" /> 

</FrameLayout> 

しかし、私はそれから任意のウェブサイトをロードしようとします。空白を取得するだけですWebViewenter image description here

Androidモニターでエラーメッセージを探してみましたが、何もありません。

は、ここで私はURLをロードするためにフラグメントに使用したコードです:ここでの問題であるかもしれない何

enter image description here

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     View view = inflater.inflate(R.layout.fragment_grade_sheet, container, false); 

     String url = "http://www.google.com/"; 
     WebView wv = (WebView)view.findViewById(R.id.webView); 
     WebSettings settings = wv.getSettings(); 
     wv.setWebChromeClient(new WebChromeClient() { 
     }); 
     final String mimeType = "text/html"; 
     final String encoding = "UTF-8"; 
     String html = ""; 
     settings.setJavaScriptEnabled(true); 
     wv.loadDataWithBaseURL(url, html, mimeType, encoding, ""); 


     return view; 
    } 

私はまた、適切なアクセス許可を追加しましたか?

答えて

1

次のコードは、私の作品:

WebView webView = (WebView) view.findViewById(R.id.webView); 
webView.setWebViewClient(new WebViewClient()); 
webView.getSettings().setJavaScriptEnabled(true); 
webView.loadUrl(url); 

あなただけWebViewClientを追加する必要があれば、私は本当に知りません。

詳細情報:WebViewClient vs WebChromeClient

0

あなたの問題は、次のとおりです。

String html = ""; 
settings.setJavaScriptEnabled(true); 
wv.loadDataWithBaseURL(url, html, mimeType, encoding, ""); 

あなたはWebViewのにあなたの空htmlの文字列を読み込んでいます。

wv.loadUrl("http://example.com/");の代わりにhtml文字列を更新してください。

loadDataWithBaseURLメソッドのAPIドキュメントをご覧ください。

関連する問題