本文整理了Java中android.webkit.WebView.loadDataWithBaseURL()
方法的一些代码示例,展示了WebView.loadDataWithBaseURL()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebView.loadDataWithBaseURL()
方法的具体详情如下:
包路径:android.webkit.WebView
类名称:WebView
方法名:loadDataWithBaseURL
暂无
代码示例来源:origin: stackoverflow.com
public class SimpleMusicStream extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
WebView wv = (WebView) findViewById(R.id.WebView01);
final String mimeType = "text/html";
final String encoding = "UTF-8";
String html = "<br /><br />Read the handouts please for tomorrow.<br /><br /><!--homework help homework" +
"help help with homework homework assignments elementary school high school middle school" +
"// --><font color='#60c000' size='4'><strong>Please!</strong></font>" +
"<img src='http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif' />";
wv.loadDataWithBaseURL("", html, mimeType, encoding, "");
}
}
代码示例来源:origin: stackoverflow.com
WebView content = (WebView) findViewById(R.id.webView1);
content.loadDataWithBaseURL(null, "<style>img{display: inline;height: auto;max-width: 100%;}</style>" + post.getContent(), "text/html", "UTF-8", null);
代码示例来源:origin: pockethub/PocketHub
private void loadSource() {
if (name != null && content != null) {
if (markdown) {
view.loadDataWithBaseURL(null, content, "text/html", "UTF-8", null);
} else {
view.loadUrl(URL_PAGE);
}
}
}
代码示例来源:origin: stackoverflow.com
String html = "<html><body>Hello, World!</body></html>";
String mime = "text/html";
String encoding = "utf-8";
WebView myWebView = (WebView)this.findViewById(R.id.myWebView);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadDataWithBaseURL(null, html, mime, encoding, null);
代码示例来源:origin: stackoverflow.com
//data == html data which you want to load
WebView webview = (WebView)this.findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadDataWithBaseURL("", data, "text/html", "UTF-8", "");
代码示例来源:origin: Justson/AgentWeb
@Override
public void loadDataWithBaseURL(final String baseUrl, final String data, final String mimeType, final String encoding, final String historyUrl) {
if (!AgentWebUtils.isUIThread()) {
mHandler.post(new Runnable() {
@Override
public void run() {
loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
}
});
return;
}
this.mWebView.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
}
代码示例来源:origin: HotBitmapGG/bilibili-android-client
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
String errorHtml = "<html><body><h2>找不到网页</h2></body></html>";
view.loadDataWithBaseURL(null, errorHtml, "text/html", "UTF-8", null);
}
代码示例来源:origin: cymcsg/UltimateAndroid
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
view.loadDataWithBaseURL("", showErrorString, "text/html", "utf-8", null);
}
代码示例来源:origin: iMeiji/Toutiao
@Override
public void onSetWebView(String url, boolean flag) {
// 是否为头条的网站
if (flag) {
webView.loadDataWithBaseURL(null, url, "text/html", "utf-8", null);
} else {
/*
ScrollView 嵌套 WebView, 导致部分网页无法正常加载
如:https://temai.snssdk.com/article/feed/index/?id=11754971
最佳做法是去掉 ScrollView, 或使用 NestedScrollWebView
*/
if (shareUrl.contains("temai.snssdk.com")) {
webView.getSettings().setUserAgentString(Constant.USER_AGENT_PC);
}
webView.loadUrl(shareUrl);
}
}
代码示例来源:origin: androidquery/androidquery
private void setup(){
String source = getSource(wv.getContext());
String html = source.replace("@src", url).replace("@color", Integer.toHexString(color));
wv.setWebViewClient(this);
//wv.setInitialScale(100);
wv.loadDataWithBaseURL(null, html, "text/html", "utf-8", null);
wv.setBackgroundColor(color);
}
代码示例来源:origin: iMeiji/Toutiao
@Override
public void onSetWebView(String url, boolean flag) {
// 是否解析网页成功
if (flag) {
webView.loadDataWithBaseURL(null, url, "text/html", "utf-8", null);
presenter.doLoadComment(bean.getAnsid());
} else {
webView.loadUrl(url);
}
}
代码示例来源:origin: wangdan/AisenWeiBo
@Override
protected void onSuccess(String s) {
super.onSuccess(s);
if (isActivityRunning()) {
// 加载网页
mWebView.loadDataWithBaseURL("https://api.weibo.com", s, "text/html", "UTF-8", "");
}
}
代码示例来源:origin: hidroh/materialistic
@Override
public void onPageFinished(android.webkit.WebView view, String url) {
super.onPageFinished(view, url);
WebView webView = (WebView) view;
if (TextUtils.equals(url, BLANK)) { // has pending reload, open corresponding URL
if (!TextUtils.isEmpty(webView.mPendingHtml)) {
view.loadDataWithBaseURL(webView.mPendingUrl, webView.mPendingHtml,
"text/html", "UTF-8", webView.mPendingUrl);
} else {
view.loadUrl(webView.mPendingUrl);
}
} else if (!TextUtils.isEmpty(webView.mPendingUrl) &&
TextUtils.equals(url, webView.mPendingUrl)) { // reload done, clear history
webView.mPendingUrl = null;
webView.mPendingHtml = null;
view.clearHistory();
}
if (mClient != null) {
mClient.onPageFinished(view, url);
}
}
代码示例来源:origin: wangdan/AisenWeiBo
@Override
protected void onSuccess(String s) {
super.onSuccess(s);
Logger.e(s);
mWebView.loadDataWithBaseURL("http://passport.weibo.cn", s, "text/html", "UTF-8", "");
GlobalContext.getInstance().getHandler().postDelayed(new Runnable() {
@Override
public void run() {
mWebView.loadUrl("javascript:fillAccount()");
ViewUtils.dismissProgressDialog();
}
}, 1500);
}
代码示例来源:origin: iMeiji/Toutiao
@Override
public void onSetWebView(String url, boolean flag) {
initWebClient();
photoView.setVisibility(View.GONE);
swipeRefreshLayout.setVisibility(View.VISIBLE);
// 是否为头条的网站
if (flag) {
webView.loadDataWithBaseURL(null, url, "text/html", "utf-8", null);
} else {
webView.loadUrl(shareUrl);
}
SlidrInterface slidrInterface = ((PhotoContentActivity) getActivity()).getSlidrInterface();
if (slidrInterface != null) {
slidrInterface.unlock();
}
}
代码示例来源:origin: ankidroid/Anki-Android
public void fillFlashcard() {
Timber.d("fillFlashcard()");
Timber.d("base url = %s", mBaseUrl);
if (mCard != null) {
CompatHelper.getCompat().setHTML5MediaAutoPlay(mCard.getSettings(), getConfigForCurrentCard().optBoolean("autoplay"));
mCard.loadDataWithBaseURL(mBaseUrl + "__viewer__.html", mCardContent.toString(), "text/html", "utf-8", null);
}
if (mShowTimer && mCardTimer.getVisibility() == View.INVISIBLE) {
switchTopBarVisibility(View.VISIBLE);
}
if (!sDisplayAnswer) {
updateForNewCard();
}
}
代码示例来源:origin: xinghongfei/LookLook
@Override
public void showZhihuStory(ZhihuStory zhihuStory) {
Glide.with(this)
.load(zhihuStory.getImage()).centerCrop()
.listener(loadListener).override(width,heigh)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(mShot);
url = zhihuStory.getShareUrl();
isEmpty=TextUtils.isEmpty(zhihuStory.getBody());
mBody=zhihuStory.getBody();
scc=zhihuStory.getCss();
if (isEmpty) {
wvZhihu.loadUrl(url);
} else {
String data = WebUtil.buildHtmlWithCss(mBody, scc, Config.isNight);
wvZhihu.loadDataWithBaseURL(WebUtil.BASE_URL, data, WebUtil.MIME_TYPE, WebUtil.ENCODING, WebUtil.FAIL_URL);
}
}
代码示例来源:origin: airbnb/AirMapView
@SuppressLint({ "SetJavaScriptEnabled", "AddJavascriptInterface" })
@Override public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_webview, container, false);
webView = (WebView) view.findViewById(R.id.webview);
mLayout = (ViewGroup) view;
WebSettings webViewSettings = webView.getSettings();
webViewSettings.setSupportZoom(true);
webViewSettings.setBuiltInZoomControls(false);
webViewSettings.setJavaScriptEnabled(true);
webViewSettings.setGeolocationEnabled(true);
webViewSettings.setAllowFileAccess(false);
webViewSettings.setAllowContentAccess(false);
webView.setWebChromeClient(new GeoWebChromeClient());
AirMapType mapType = AirMapType.fromBundle(getArguments());
webView.loadDataWithBaseURL(mapType.getDomain(), mapType.getMapData(getResources()),
"text/html", "base64", null);
webView.addJavascriptInterface(new MapsJavaScriptInterface(), "AirMapView");
return view;
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldRecordLastLoadDataWithBaseURL() throws Exception {
webView.loadDataWithBaseURL("base/url", "<html><body><h1>Hi</h1></body></html>", "text/html", "utf-8", "history/url");
ShadowWebView.LoadDataWithBaseURL lastLoadData = shadowOf(webView).getLastLoadDataWithBaseURL();
assertThat(lastLoadData.baseUrl).isEqualTo("base/url");
assertThat(lastLoadData.data).isEqualTo("<html><body><h1>Hi</h1></body></html>");
assertThat(lastLoadData.mimeType).isEqualTo("text/html");
assertThat(lastLoadData.encoding).isEqualTo("utf-8");
assertThat(lastLoadData.historyUrl).isEqualTo("history/url");
}
代码示例来源:origin: airbnb/AirMapView
@Override public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
MapboxWebMapType mapType = MapboxWebMapType.fromBundle(getArguments());
webView.loadDataWithBaseURL(mapType.getDomain(), mapType.getMapData(getResources()),
"text/html", "base64", null);
return view;
}
内容来源于网络,如有侵权,请联系作者删除!