Android programming-Basic webview control usage

Source: Internet
Author: User

Recently, I 've concentrated on reading the relevant chapters on the graphic user interface of Android Program Design (Beijing hang Publishing House), focusing on the basic knowledge of Android GUI in my favorite UI field.

The webview control provides an embedded browser to display local HTML or web pages.

Step 1 // main. xml

<WebView    android:id="@+id/html"    android:layout_width="fill_parent"    android:layout_height="280px"/> 

Step 2. // main class. Java

@ Overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); webview web = (webview) findviewbyid(r.id.html); web. getsettings (). setjavascriptenabled (true); // used to support javascriptweb. loadurl ("http://www.baidu.com"); // access an external URL

Step 3. // androidmanifest. xml

If this row is not permitted, the webpage cannot be found when accessing the external website. This license is also required when writing socket communication programs.

</application>    <uses-permission android:name="android.permission.INTERNET"/>

Step 4. // main class. Java

The browser view displayed by default in the normal webview control does not have a webpage loading progress bar or announcement. After clicking the hyperlink on the first page, the system will call its own browser process for next network access, this is not in line with our programming and usage habits. You can customize the operations by rewriting the following methods.

// This method can handle some Web operations when webview is loaded and loaded. setwebchromeclient (New webchromeclient () {@ overridepublic void onprogresschanged (webview view, int newprogress) {If (newprogress = 100) {// set the title of the activity, // You can also perform other operations based on your needs. settitle ("loaded");} else {settitle ("loading ....... ") ;}}}); web. setwebviewclient (New webviewclient () {@ overridepublic Boolean shouldoverrideurlloading (webview view, string URL) {// rewrite this method to indicate that clicking the link in the webpage is still redirected in the current webview, do not jump to view in the browser. loadurl (URL); Return true ;}

The school is about to begin. Three main roads are taught in the canteen, and the young faces are as young as we were two years ago.

At that time, I was still naive and always fantasized about the countless possibilities of the future.

Gradually, we all know that any possibility needs to be realized through our own efforts.

Good, bad, all by yourself.

What life looks like, in fact, they all draw a stroke with a paint brush.

No one can make me a bright future, but I can.

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.