Android load local HTML page

Source: Internet
Author: User
Tags dateformat

1. Create a raw folder under Res to place HTML files.

2. Create an HTML file in raw: mypage.html

<! Doctype HTML public "-// W3C // dtd html 4.01 // en" "http://www.w3.org/TR/REC-html40/strict.dtd">
<HTML>
<Head>
<Title> actuate viewer </title>
</Head>

<Body>
<H1> This is body !! </H1>
<H2> This is Franch !! Adobe a annoncé hier que un comprim é
Optimis é e-Flash Player 10.2 sera pr é-install é sur certains des
Ardoises, mais il sera un t é chargement OTA pour la plupart des
Tablettes honeycomb Android disponible en «Quelques semaines». ce que
Cela signifie est que le dispositif de lancement de honeycomb, le xoom
Motorola qui sera disponible ce jeudi, VA navire sans Flash Player. En
Fait une annonce pour le xoom Verizon é quip é cot es... </H2>
<A href = "http://www.blabla.cn" target = "_ blank"> open a new page1. </a>
<A href = "http://www.blabla.cn" target = "_ Self"> open a new page2. </a>
</Body>
</Html>

3. Android activity:

Private webview mwebview;

/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );

Mwebview = (webview) findviewbyid (R. Id. agendize );
Mwebview. setwebviewclient (New mywebviewclient ());
Mwebview. setwebchromeclient (New mywebchromeclient ());
Findviewbyid (R. Id. btnsend). setonclicklistener (New onclicklistener (){

@ Override
Public void onclick (view v ){

// For email
// String HL =
// "<HTML> <title> AAA </title> <body> It is body </body> // Intent it = new intent (intent. action_send );
// It. putextra (intent. extra_text, HTML. fromhtml (HL ));
// It. settype ("text/plain ");
// Startactivity (intent. createchooser (it,
// "Choose email client "));

// For webview
Mwebview. loadurl ("file: // android_res/raw/mypage.html ");
}
});
}

/* Mobile End */

String convertdatetostring (date, string format ){
Dateformat = new simpledateformat (format );
Return dateformat. Format (date );
}

Public class mywebviewclient extends webviewclient {

@ Override
Public Boolean shouldoverrideurlloading (webview view, string URL ){
View. loadurl (URL );
Return true;
}

@ Override
Public void onpagestarted (webview view, string URL, bitmap favicon ){
}

@ Override
Public void onpagefinished (webview view, string URL ){
}
}

Private class mywebchromeclient extends webchromeclient {

@ Override
Public void onprogresschanged (webview view, int newprogress ){
}

@ Override
Public void onreceivedtitle (webview view, String title ){
Super. onreceivedtitle (view, title );
}
}

Related Article

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.