Webview不会加载整个网站

时间:2016-04-12 18:53:32

标签: android android-fragments

当我尝试使用webview加载网站时,页面会加载。但是,页面不会加载所有内容。我得到了PHP部分和Youtubevídeo但它没有出现。这是我的代码:

public class ChatFragment extends Fragment {


public ChatFragment() {
    // Required empty public constructor
}


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

    String url = "mywebpath/index.php"; // It has the http part
    WebView webView = (WebView) view.findViewById(R.id.chat);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
    webView.setWebViewClient(new WebViewClient());
    webView.setWebChromeClient(new WebChromeClient());
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    if (Build.VERSION.SDK_INT >= 19) {
        webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }
    else {
        webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

    WebSettings webSettings = webView.getSettings();
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);

    return view;
}

这是网站:http://i.imgur.com/Tk8UIvL.jpg

这是webview结果:http://i.imgur.com/reDPlx1.png

非常感谢您的关注

P.S。聊天从php部分开始,然后出现一个div。

2 个答案:

答案 0 :(得分:0)

试一试!!!

 foreach (Section section in aDoc.Sections)
            {
                //Get the header range and add the header details.
                var headerRange = section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                headerRange.Fields.Add(headerRange, WdFieldType.wdFieldPage);
                headerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                headerRange.Font.ColorIndex = WdColorIndex.wdBlack;
                headerRange.Font.Size = 14;
                headerRange.Font.Name = "Arial";
                headerRange.Font.Bold = 1;
                headerRange.Text = Some Header Here;
                headerRange.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
           }
AndroidMainfest中的

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                     Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_chat, container, false);
String url = "mywebpath/index.php"; // It has the http part
WebView mWebView = (WebView) view.findViewById(R.id.chat);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().getPluginState(); 
if (Build.VERSION.SDK_INT < 8) {
mWebView.getSettings().setPluginsEnabled(true); 
} else { 
mWebView.getSettings().setPluginState(PluginState.ON); 
}
mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
 }
mWebView.loadUrl(url);
return view;
}

如果不起作用。试试这个。 (替换mWebview.loadUrl)

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>   
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

或者

mWebview.loadData(url, "text/html", "utf-8");

答案 1 :(得分:0)

哦,哦!您必须为移动版

创建您的网站

EG:

vsersion浏览器:for Browser

版本移动版:for mobile