63:webview common usage of Android development step by step

Source: Internet
Author: User

WebView is a common component, especially if the current H5 is so popular, this article describes the general usage of WebView in the project. Generally webview loading process before the current network to make a judgment, without the case of the network to give a hint. There is a network case with a ProgressBar showing the current progress, OK, on the code.

First step: Design the page

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent "    android:o rientation= "vertical" >    <include layout= "@layout/layout_head"/>   <progressbar          android:id= "@+id/pb"          style= "android:attr/progressbarstylehorizontal"          android:layout_width= "Fill_parent          " android:layout_height= "2dip"          android:indeterminateonly= "false"          android:max= "          android: progressdrawable= "@drawable/progress_bar_states_new" >      </ProgressBar>      <webview        Android:id= "@+id/webview"        android:layout_width= "match_parent"        android:layout_height= "match_parent"/ ></LinearLayout>


Step Two: Write activity


/** * */package com.android.inputmethod.latin.activity;import android.app.activity;import Android.os.Bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.webkit.webchromeclient;import Android.webkit.webview;import Android.widget.linearlayout;import Android.widget.progressbar;import Android.widget.textview;import com.android.inputmethod.latin.r;import com.dotc.util.networkutil;/** * @author Figo *    */public class Commonproblemactivity extends Activity {private WebView wb;    ProgressBar PB;    Private LinearLayout Mlayoutback;    Private TextView Mtvtitle; @Override protected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method stub super.o        Ncreate (savedinstancestate);           Setcontentview (R.layout.activity_common_problem);        } @Override protected void Onresume () {//TODO auto-generated Method Stub super.onresume ();    Initview (); } private void Initview () {try {                      PB = (ProgressBar) Findviewbyid (R.ID.PB);              Pb.setmax (100);            Mlayoutback = (linearlayout) Findviewbyid (r.id.layout_back); Mlayoutback.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View ar                G0) {finish ();            }            });            Mtvtitle = (TextView) Findviewbyid (r.id.txt_title);            Mtvtitle.settext (getString (R.string.lbl_common_problem));            This write will jump directly to the browser//Wb.loadurl ("http://www.baidu.com");            Use the Webviewclient Web page to display WB = (WebView) Findviewbyid (R.id.webview) in the current activity;              Wb.getsettings (). Setjavascriptenabled (True);                Wb.getsettings (). Setsupportzoom (True);              Wb.getsettings (). Setbuiltinzoomcontrols (True);              Wb.setwebchromeclient (New Webviewclient ()); if (!          Networkutil.isnetworkuseful (Commonproblemactivity.this))  {String customhtml = "

63:webview common usage of Android development step by step

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.