本文整理汇总了Java中android.webkit.WebView.loadDataWithBaseURL方法的典型用法代码示例。如果您正苦于以下问题:Java WebView.loadDataWithBaseURL方法的具体用法?Java WebView.loadDataWithBaseURL怎么用?Java WebView.loadDataWithBaseURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.webkit.WebView
的用法示例。
在下文中一共展示了WebView.loadDataWithBaseURL方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
getSupportActionBar().setTitle(getString(R.string.about));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
progressBar = (ProgressBar) findViewById(R.id.progress);
progressBar.getIndeterminateDrawable()
.setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN);
info_web = (WebView) findViewById(R.id.webview_company_info);
info_web.setBackgroundColor(Color.TRANSPARENT);
info_web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
info_web.setWebViewClient(new myWebClient());
info_web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
info_web.getSettings().setJavaScriptEnabled(true);
info_web.getSettings().setDefaultFontSize((int) getResources().getDimension(R.dimen.about_text_size));
String infoText = getString(R.string.company_info_web);
info_web.loadDataWithBaseURL("file:///android_asset/fonts/", getWebViewText(infoText), "text/html", "utf-8", null);
}
示例2: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
getSupportActionBar().setTitle(getString(R.string.about));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
progressBar = (ProgressBar) findViewById(R.id.progress);
progressBar.getIndeterminateDrawable()
.setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN);
info_web = (WebView) findViewById(R.id.webview_company_info);
info_web.setBackgroundColor(Color.TRANSPARENT);
info_web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
info_web.setWebViewClient(new myWebClient());
info_web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
info_web.getSettings().setJavaScriptEnabled(true);
String infoText = getString(R.string.company_info_web);
info_web.loadDataWithBaseURL("file:///android_asset/fonts/", getWebViewText(infoText), "text/html", "utf-8", null);
}
示例3: init
import android.webkit.WebView; //导入方法依赖的package包/类
private void init() {
sharedPreferencesUtils = new SharedPreferencesUtils(context);
view = LayoutInflater.from(context).inflate(R.layout.dialog_html,null);
this.setContentView(view);
this.setTitle(title);
webView = (WebView) view.findViewById(R.id.dialog_html_webview);
webView.loadDataWithBaseURL(null,readAssets(context,"about.html"),
"text/html", "utf-8", null);
webView.setWebChromeClient(new WebChromeClient());
this.setPositiveButton(ok, new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}
示例4: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_aboutus);
Intent incoming = getIntent();
Bundle extras = incoming.getExtras();
String uri = "html/about.html";
if(extras != null){
uri = extras.getString(EXTRA_HTML_URI);
}
mWebView = (WebView) findViewById(R.id.webView);
mCloseBtn = (ImageButton) findViewById(R.id.closeButton);
mCloseBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
InputStream is;
String htmlData = "";
try {
is = this.getAssets().open(uri);
BufferedReader r = new BufferedReader(new InputStreamReader(is));
StringBuilder stringBuilder = new StringBuilder();
String line;
while( (line=r.readLine()) != null ) {
stringBuilder.append(line);
}
htmlData = stringBuilder.toString();
} catch( IOException error ) {}
mWebView.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "utf-8", "about:blank");
}
示例5: setWebView
import android.webkit.WebView; //导入方法依赖的package包/类
public static void setWebView(final WebView webView, String content) {
content = content.replace(" style=\"", " style\\=\"");
webView.getSettings().setJavaScriptEnabled(false);
webView.loadDataWithBaseURL(null, "<style>body{margin:0;padding:0;word-wrap:break-word;width:100%;}img{display:inline;height:auto;max-width:100%;}a{color:#F44336;}</style><body>" + content + "</body>", "text/html", "utf-8", null);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
webView.getContext().startActivity((new Intent(webView.getContext(), BrowserActivity.class)).putExtra(Constant.URL, url));
return true;
}
});
}
示例6: onReceivedSslError
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
Log.w(TAG, "SSL error (error: " + error.getPrimaryError() + " host: " +
// Only show host to avoid leaking private info.
Uri.parse(error.getUrl()).getHost() + " certificate: " +
error.getCertificate() + "); displaying SSL warning.");
final String html = String.format(SSL_ERROR_HTML, getString(R.string.ssl_error_warning),
getString(R.string.ssl_error_example), mBrowserBailOutToken,
getString(R.string.ssl_error_continue));
view.loadDataWithBaseURL(INTERNAL_ASSETS, html, "text/HTML", "UTF-8", null);
}
示例7: onCreateView
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_initiative_detail, container, false);
final WebView content = (WebView) rootView.findViewById(R.id.initiative_web_view);
button = (Button) rootView.findViewById(R.id.sign_button);
// Cargamos el contenido en el WebView.
content.loadDataWithBaseURL("", initiative.toHtmlString(), "text/html", "UTF-8", "");
addListenerOnButton();
return rootView;
}
示例8: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_noticia);
//Pega a notícia passada pela ActivityPrincipal
mNoticia = (Noticia)getIntent().getExtras().get("noticia");
//Obtem da View
mToolbar = (Toolbar) findViewById(R.id.tb_noticias);
mToolbar.setTitle(mNoticia.getTitulo());
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
//Obtem da View
mImageView = (ImageView) findViewById(R.id.iv_noticias);
//Carrega a imagem com a biblioteca Picasso
Picasso.with(this).load(Uri.parse(Utils.getUrlApiThumbnail(this).replace("$tipo", "noticias").replace("$id", String.valueOf(mNoticia.getId()))+"&thumb=false")).placeholder(R.drawable.no_avatar).into(mImageView);
//Obtem da View
mWebView = (WebView) findViewById(R.id.web_noticias);
//Carrega o conteúdo
mWebView.loadDataWithBaseURL("file:///android_asset/","<link rel=\"stylesheet\" type=\"text/css\" href=\"estilo.css\" />"+mNoticia.getConteudo(),"text/html", "UTF-8", null);
//Permite Javascript e outros fatores
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setAllowContentAccess(true);
WebSettings webSettings = mWebView.getSettings();
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setUseWideViewPort(true);
mWebView.setWebChromeClient(new WebChromeClient() {});
}
示例9: setSource
import android.webkit.WebView; //导入方法依赖的package包/类
@ReactProp(name = "source")
public void setSource(WebView view, @Nullable ReadableMap source) {
if (source != null) {
if (source.hasKey("html")) {
String html = source.getString("html");
if (source.hasKey("baseUrl")) {
view.loadDataWithBaseURL(
source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING, null);
} else {
view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
}
return;
}
if (source.hasKey("uri")) {
String url = source.getString("uri");
String previousUrl = view.getUrl();
if (previousUrl != null && previousUrl.equals(url)) {
return;
}
if (source.hasKey("method")) {
String method = source.getString("method");
if (method.equals(HTTP_METHOD_POST)) {
byte[] postData = null;
if (source.hasKey("body")) {
String body = source.getString("body");
try {
postData = body.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
postData = body.getBytes();
}
}
if (postData == null) {
postData = new byte[0];
}
view.postUrl(url, postData);
return;
}
}
HashMap<String, String> headerMap = new HashMap<>();
if (source.hasKey("headers")) {
ReadableMap headers = source.getMap("headers");
ReadableMapKeySetIterator iter = headers.keySetIterator();
while (iter.hasNextKey()) {
String key = iter.nextKey();
if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) {
if (view.getSettings() != null) {
view.getSettings().setUserAgentString(headers.getString(key));
}
} else {
headerMap.put(key, headers.getString(key));
}
}
}
view.loadUrl(url, headerMap);
return;
}
}
view.loadUrl(BLANK_URL);
}
示例10: onCalcPlotCompleted
import android.webkit.WebView; //导入方法依赖的package包/类
public void onCalcPlotCompleted(String strFormattedInput, long lTaskTriggerTime, String strTaskType, String strOutput) {
mstrarrayTaskAndOutput[0] = strTaskType;
mstrarrayTaskAndOutput[1] = strOutput;
// chart file name is added later on.
String strChartFileName = "";
if (strTaskType.equalsIgnoreCase("plot") || strTaskType.equalsIgnoreCase("recognize-plot")) {
strChartFileName = ActivityChartDemon.getChartFileName(
ChartOperator.addEscapes(getString(R.string.chart_name_default)).trim(),
lTaskTriggerTime);
}
String strOutputProcessed = mstrarrayTaskAndOutput[1].replace(SELECTED_STORAGE_PATH_UNIMATCH,
AndroidStorageOptions.getSelectedStoragePath());
WebView wvOutput = (WebView) findViewById(R.id.webviewSmartMathOutput);
if (strTaskType.equalsIgnoreCase("recognize-plot") || strTaskType.equalsIgnoreCase("recognize-calculate")) {
if (mshistoricalRecMgr.getRecordsLen() > 0 && mshistoricalRecMgr.getFirstRecord().mstrTaskType.equals("recognize")) {
// change record because last recognized record is a temporary record for the recognize step.
mshistoricalRecMgr.getFirstRecord().setHistoricalRecordItem(strFormattedInput, strTaskType, strOutput, strChartFileName);
} else {
mshistoricalRecMgr.addRecord(strFormattedInput, strTaskType, strOutput, strChartFileName, ActivitySettings.msnNumberofRecords);
}
String strConfirm = "<p>" + getString(R.string.please_confirm_recognized_result_and_calculation_result)
+ "<a href=\"" + ActivitySmartCalc.AOPER_URL_HEADER + ActivitySmartCalc.EMAIL_UNSATISFACTORY_RECOG + "\">"
+ getString(R.string.here) + "</a>" + getString(R.string.stop_charater) + "</p>";
wvOutput.loadDataWithBaseURL("file:///android_asset/mathscribe/index.html",
OUTPUT_HEAD_STRING + mstrFontSize + OUTPUT_SIZE_UNIT_STRING + strConfirm + strOutputProcessed + OUTPUT_TAIL_STRING,
"text/html", "utf-8", "");
} else {
mshistoricalRecMgr.addRecord(strFormattedInput, strTaskType, strOutput, strChartFileName, ActivitySettings.msnNumberofRecords);
wvOutput.loadDataWithBaseURL("file:///android_asset/mathscribe/index.html",
OUTPUT_HEAD_STRING + mstrFontSize + OUTPUT_SIZE_UNIT_STRING + strOutputProcessed + OUTPUT_TAIL_STRING,
"text/html", "utf-8", "");
}
/* do not clear the input text box for next calculation */
// EditText txtInput = (EditText)findViewById(R.id.edtSmartMathInput);
// txtInput.setText("");
}
示例11: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
mHelpView = (WebView) findViewById(R.id.help_view);
mHelpView.loadDataWithBaseURL("x-data://base", getResources().getString(R.string.help_content), "text/html", "utf-8", null);
mHelpView.setBackgroundColor(Color.BLACK);
setTextSize();
}
示例12: onCreateView
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_info, container, false);
String webViewHtml = getArguments().getString(WEBVIEW_HTML);
mWebView = (WebView) v.findViewById(R.id.infoActivityWV);
mWebView.loadDataWithBaseURL(null, webViewHtml, "text/html", "utf-8", null);
return v;
}
示例13: loadWebView
import android.webkit.WebView; //导入方法依赖的package包/类
private void loadWebView(String data, WebView webView) {
webView.loadDataWithBaseURL(
ANDROID_ASSET,
data,
"text/html",
"utf-8",
null);
}
示例14: setRecognizedInput
import android.webkit.WebView; //导入方法依赖的package包/类
public void setRecognizedInput(String strRecogResult, String strRecogErr) {
EditText txtInput = (EditText)findViewById(R.id.edtSmartMathInput);
// if strRecogResult is null, we do not change input text.
if (strRecogResult != null) {
txtInput.setText(strRecogResult); // clear input and set text.
} else {
txtInput.setText("");
}
String strConfirm = "<p>" + getString(R.string.please_confirm_recognized_result_and_calculation_result)
+ "<a href=\"" + AOPER_URL_HEADER + EMAIL_UNSATISFACTORY_RECOG + "\">"
+ getString(R.string.here) + "</a>" + getString(R.string.stop_charater) + "</p>";
String strRecogExprsOutput = "";
if (strRecogErr == null || strRecogErr.length() == 0) {
if (strRecogResult == null || strRecogResult.length() == 0) {
// output is empty
strRecogExprsOutput = "<p>" + getString(R.string.no_valid_expr_recognized) + "</p>\n";
} else {
// output is not empty
strRecogExprsOutput = "<p>" + getString(R.string.recognized_result) + "</p>";
String[] strarrayExprs = txtInput.getText().toString().split("\n");
String strRecognizedExprColor = "color:#008000;", strInvalidExprColor = "color:#800000;";
for (int idx = 0; idx < strarrayExprs.length; idx ++) {
/* show the expression(s) */
CurPos curpos = new CurPos();
curpos.m_nPos = 0;
AbstractExpr aexpr = new AEInvalid();
try {
aexpr = ExprAnalyzer.analyseExpression(strarrayExprs[idx], curpos);
strRecogExprsOutput += "<p><a href=\"" + AbstractExprConverter.convtPlainStr2QuotedUrl(strarrayExprs[idx])
+ "\" style=\"text-decoration: none;" + strRecognizedExprColor + "\">$"
+ AbstractExprConverter.convtAExpr2JQMath(aexpr) + "$</a></p>\n";
} catch (Exception e) {
strRecogExprsOutput += "<p><a href=\"" + AbstractExprConverter.convtPlainStr2QuotedUrl(strarrayExprs[idx])
+ "\" style=\"text-decoration: none;" + strInvalidExprColor + "\">$"
+ AbstractExprConverter.convtPlainStr2JQMathNoException(strarrayExprs[idx]) + "$</a></p>\n";
strRecogExprsOutput += "<p> <big>⇒</big> " + getString(R.string.invalid_expr_to_analyse) + " ";
strRecogExprsOutput += getString(R.string.please_modify_the_input_expression) + "</p><p>"
+ TextUtils.htmlEncode(strarrayExprs[idx]) + "</p>\n";
}
}
}
} else {
// recognition error.
strRecogExprsOutput = "<p>" + strRecogErr + "</p>\n";
}
mstrarrayTaskAndOutput[0] = "recognize";
mstrarrayTaskAndOutput[1] = strRecogExprsOutput; // save it to mstrOutput so that it can be reloaded after rotation.
mshistoricalRecMgr.addRecord(strRecogResult, mstrarrayTaskAndOutput[0], mstrarrayTaskAndOutput[1], "", ActivitySettings.msnNumberofRecords);
WebView wvOutput = (WebView) findViewById(R.id.webviewSmartMathOutput);
wvOutput.loadDataWithBaseURL("file:///android_asset/mathscribe/index.html",
OUTPUT_HEAD_STRING + mstrFontSize + OUTPUT_SIZE_UNIT_STRING + strConfirm + strRecogExprsOutput + OUTPUT_TAIL_STRING,
"text/html", "utf-8", "");
// hide the soft keyboard and inputpad so that recognizing result can be shown.
if (mnSoftKeyState == ENABLE_SHOW_SOFTKEY) {
setSoftKeyState(txtInput, ENABLE_HIDE_SOFTKEY);
} else if (mnSoftKeyState == ENABLE_SHOW_INPUTPAD) {
setSoftKeyState(txtInput, ENABLE_HIDE_INPUTPAD);
}
}
示例15: loadDataWithCss
import android.webkit.WebView; //导入方法依赖的package包/类
public static void loadDataWithCss(WebView webView, String html, String cssPath){
String css = !TextUtils.isEmpty(cssPath)? String.format(CSS_LINK_PLACE_HOLDER, cssPath): "";
webView.loadDataWithBaseURL(null, css + html, "text/html", "UTF-8", null);
}