【发布时间】:2018-09-12 08:08:24
【问题描述】:
我正在使用下面的代码用本地 html 文件填充我的 WebView,但它在某些设备中看起来不错,但最近我注意到在某些设备中,例如 Colors X114、@987654327 @ 出现一秒钟,然后一切消失并出现白色空白屏幕。
代码:
package com.nepalpolice.mnemonics;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
/**
* Created by Sagar on 2017/09/23. yo chai menupage ko Fragments ko lagi
*/
public class Homepage extends Fragment {
WebView myWebView;
private LinearLayout container;
private Button nextButton, closeButton;
private EditText findBox;
public Homepage() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_homepage, container, false);
String url = getArguments().getString("url");
myWebView=(WebView)rootView.findViewById(R.id.webview);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
myWebView.getSettings().setLoadsImagesAutomatically(true);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.setInitialScale(1);
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
WebSettings webSettings = myWebView.getSettings();
myWebView.loadUrl(url);
return rootView;
}
public static String changedHeaderHtml(String htmlText) {
String head = "<head><meta name=\"viewport\" content=\"width=device-width, user-scalable=yes\" /></head>";
String closedTag = "</body></html>";
String changeFontHtml = head + htmlText + closedTag;
return changeFontHtml;
}
}
这就是它出现或应该出现的方式
但它在某些设备中的显示方式。
我将 url 作为字符串传递,如下所示
args3.putString("url1", "file:///android_asset/b/dbpm.html");
【问题讨论】:
标签: java android android-studio webview android-webview