当前位置: 首页>>代码示例>>Java>>正文


Java WebView.loadData方法代码示例

本文整理汇总了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();
}
 
开发者ID:hichemcesar24,项目名称:Weather-Android,代码行数:28,代码来源:MainActivity.java

示例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");
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:23,代码来源:ViewActivity.java

示例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);
}
 
开发者ID:seven332,项目名称:android-recaptcha,代码行数:14,代码来源:RecaptchaV1Task.java

示例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");
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:8,代码来源:Help.java

示例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);
    }
}
 
开发者ID:DSM-DMS,项目名称:DMS,代码行数:32,代码来源:AppcontentArticleActivity.java

示例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);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:9,代码来源:NetworkActivity.java

示例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);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:8,代码来源:NetworkActivity.java

示例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");
}
 
开发者ID:SysdataSpA,项目名称:SDHtmlTextView,代码行数:10,代码来源:WebViewActivity.java

示例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);
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:60,代码来源:ReactWebViewManager.java

示例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);
}
 
开发者ID:lorienzhang,项目名称:WLLayout,代码行数:30,代码来源:MainActivity.java

示例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);
}
 
开发者ID:DeValladolid,项目名称:sportspress-android-app,代码行数:42,代码来源:Post.java

示例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);
}
 
开发者ID:Snooze986,项目名称:SonoESEO-Android,代码行数:55,代码来源:ArticleActivity.java


注:本文中的android.webkit.WebView.loadData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。