本文整理汇总了Java中android.webkit.WebView.loadData方法的典型用法代码示例。如果您正苦于以下问题:Java WebView.loadData方法的具体用法?Java WebView.loadData怎么用?Java WebView.loadData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.webkit.WebView
的用法示例。
在下文中一共展示了WebView.loadData方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: aboutDialog
import android.webkit.WebView; //导入方法依赖的package包/类
private void aboutDialog() {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("SmartCity");
final WebView webView = new WebView(this);
String about = "<p>A Smart city , opensource weather app.</p>" +
"<p>Developed by <a href='mailto:[email protected]'>Hichem Romdhane</a></p>";
TypedArray ta = obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary, R.attr.colorAccent});
String textColor = String.format("#%06X", (0xFFFFFF & ta.getColor(0, Color.BLACK)));
String accentColor = String.format("#%06X", (0xFFFFFF & ta.getColor(1, Color.BLUE)));
ta.recycle();
about = "<style media=\"screen\" type=\"text/css\">" +
"body {\n" +
" color:" + textColor + ";\n" +
"}\n" +
"a:link {color:" + accentColor + "}\n" +
"</style>" +
about;
webView.setBackgroundColor(Color.TRANSPARENT);
webView.loadData(about, "text/html", "UTF-8");
alert.setView(webView, 32, 0, 32, 0);
alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.show();
}
示例2: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.help);
WebView vw = (WebView) findViewById(R.id.help);
InputStream in = getResources().openRawResource(getIntent().getIntExtra("content", -1));
StringWriter builder = new StringWriter(1000);
BufferedReader r = new BufferedReader(new InputStreamReader(in));
String s;
try {
while ((s = r.readLine()) != null)
builder.append(s);
r.close();
} catch (IOException e) {
e.printStackTrace(new PrintWriter(builder));
}
vw.loadData(builder.toString(),
"text/html", "UTF-8");
}
示例3: RecaptchaV1Task
import android.webkit.WebView; //导入方法依赖的package包/类
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
public RecaptchaV1Task(Context context, String challenge, Handler handler, RecaptchaV1.RecaptchaCallback callback) {
this.handler = handler;
this.callback = callback;
webView = new WebView(context.getApplicationContext());
webView.setWebViewClient(new RecaptchaClient());
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(this, "Android");
webView.loadData(HTML_BODY_1 + challenge + HTML_BODY_2, HTML_MIME_TYPE, HTML_ENCODING);
}
示例4: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webview = new WebView(this);
setContentView(webview);
webview.loadData(getString(getResources().openRawResource(R.raw.help)), "text/html", "utf8");
}
示例5: bind
import android.webkit.WebView; //导入方法依赖的package包/类
/**
* sets text of article
*
* @param appcontent Appcontent object that contains information of article
*/
private void bind(final Appcontent appcontent) {
TextView titleTV = (TextView) findViewById(R.id.tv_appcontent_article_title);
TextView writerTV = (TextView) findViewById(R.id.tv_appcontent_article_writer);
TextView dateTV = (TextView) findViewById(R.id.tv_appcontent_article_date);
WebView contentWV = (WebView) findViewById(R.id.wv_appcontent_article_content);
titleTV.setText(appcontent.getTitle());
writerTV.setText(appcontent.getWriter());
dateTV.setText(appcontent.getDate());
contentWV.loadData(appcontent.getContent(), "text/html; charset=UTF-8", null);
mFAB = (FloatingActionButton) findViewById(R.id.fab_appcontent_article);
final List<Attachment> attachmentList = appcontent.getAttachmentList();
if (attachmentList != null && attachmentList.size() != 0) {
mFAB.setImageResource(R.drawable.ic_file_download_white_24dp);
mFAB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DownloadAttachmentDialogFragment
.newInstance(AppcontentArticleActivity.this, attachmentList)
.show(getSupportFragmentManager(), null);
}
});
mFAB.setVisibility(View.VISIBLE);
}
}
示例6: showErrorPage
import android.webkit.WebView; //导入方法依赖的package包/类
private void showErrorPage() {
setContentView(R.layout.main);
// The specified network connection is not available. Displays error message.
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadData(getResources().getString(R.string.connection_error),
"text/html", null);
}
示例7: onPostExecute
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onPostExecute(String result) {
setContentView(R.layout.main);
// Displays the HTML string in the UI via a WebView
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadData(result, "text/html", null);
}
示例8: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
String tableHtml = getIntent().getStringExtra(EXTRA_TABLE_HTML);
WebView webView = (WebView) findViewById(R.id.web_view);
webView.loadData(tableHtml, "text/html", "UTF-8");
}
示例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: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wl = (WLLayout) findViewById(R.id.wl);
// WebView
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadData(htmlString, "text/html", "utf-8");
WebViewClient webViewClient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
};
myWebView.setWebViewClient(webViewClient);
// ListView
for (int i = 0; i < 60; i++) {
list.add("评论:" + i);
}
ListView lv = (ListView) findViewById(R.id.list_view);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
lv.setAdapter(adapter);
View header = LayoutInflater.from(this).inflate(R.layout.header_view, lv, false);
lv.addHeaderView(header);
}
示例11: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.post);
final String id = getIntent().getExtras().getString("id");
title = (TextView) findViewById(R.id.title);
content = (WebView)findViewById(R.id.content);
progressDialog = new ProgressDialog(Post.this);
progressDialog.setMessage("Loading...");
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.show();
String url = "https://www.balonmanozaratan.com/wp-json/sportspress/v2/events/"+id+"?fields=title,content";
StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
gson = new Gson();
mapPost = (Map<String, Object>) gson.fromJson(s, Map.class);
mapTitle = (Map<String, Object>) mapPost.get("title");
mapContent = (Map<String, Object>) mapPost.get("content");
title.setText(mapTitle.get("rendered").toString());
content.loadData(mapContent.get("rendered").toString(),"text/html","UTF-8");
progressDialog.dismiss();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
progressDialog.dismiss();
Toast.makeText(Post.this, id, Toast.LENGTH_LONG).show();
}
});
RequestQueue rQueue = Volley.newRequestQueue(Post.this);
rQueue.add(request);
}
示例12: onCreate
import android.webkit.WebView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
setContentView(R.layout.activity_article);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(getString(R.string.emptyField));
if (Content.article.getTitle() != null) {
actionBar.setTitle(Content.article.getTitle());
}
}
ImageView imgAvatar = (ImageView) findViewById(R.id.imgAvatar);
String link = APIConstants.SONO_AVATAR + Content.article.getAuthorAvatar();
Picasso.with(this).load(link).placeholder(R.drawable.ic_user).error(R.drawable.ic_user)
.into(imgAvatar);
TextView txtTitle = (TextView) findViewById(R.id.txtTitle);
txtTitle.setText(getString(R.string.emptyField));
if (Content.article.getTitle() != null) {
txtTitle.setText(Content.article.getTitle());
}
TextView txtAuthor = (TextView) findViewById(R.id.txtAuthor);
txtAuthor.setText(getString(R.string.emptyField));
if (Content.article.getAuthor() != null) {
txtAuthor.setText(Content.article.getAuthor());
}
TextView txtDate = (TextView) findViewById(R.id.txtDate);
String dateString = getString(R.string.emptyField);
if (Content.article.getDate() != null) {
dateString = new SimpleDateFormat("EEEE d MMMM yyyy")
.format(Content.article.getDate());
}
txtDate.setText(dateString);
WebView wvContent = (WebView) findViewById(R.id.wvContent);
wvContent.setBackgroundColor(Color.TRANSPARENT);
wvContent.setHapticFeedbackEnabled(false);
wvContent.getSettings().setDefaultFontSize(15);
wvContent.setClickable(false);
wvContent.setLongClickable(false);
wvContent.getSettings().setJavaScriptEnabled(false);
wvContent.loadData("" +
"<body style=\"text-align: justify;\">" + Content.article.getContent()
.replace("\n", "<br/>") + "</body>",
"text/html; charset=UTF-8", null);
}