Use of html, js, and css in combination with Android

Source: Internet
Author: User


The following example shows how to share your experience with a friend on the Internet. I posted this article, so you should pay more attention and make fewer mistakes.

Important:

Key code in android:

Webview. getSettings (). setJavaScriptEnabled (true );

Webview. addJavascriptInterface (object, "name"); // Add the object Name = "name" to the object. If the object is this, It is window. name.

Webview. loadUrl ("file: // android_asset/index.html"); // note that the resource is located in the same folder as res.

Call the method code in android in js or html:

For example:

Or the method () in window. name. java in js ();

The function Method of calling js in android:

Callfunction (){

Webview. loadUrl ("javascript: function ()");

}

 

Note that many data types are not recognized in js. It is best to encapsulate them in android to provide necessary method interfaces. For example, if you upload the list to js, you cannot obtain the elements in js.

AddJavascriptInterface: the Java object and method to be bound in the addJavascriptInterface method must run in another thread, and cannot run in the Construction thread, that is, cannot run in the current activity thread, is to bind this method to the page, js can also call

 

Explanation in this document:

Use this function to bind an object to Javascript so that the methods can be accessed from Javascript.

The Java object that is bound runs in another thread and not in the thread that it was constructed in.

In fact, the above are all nonsense:

Important: The following two connections

All of them are for reference:

1:. http://ysongren.blog.163.com/blog/static/6154220720109211020410/

2. http://blog.csdn.net/hanyuwei0/article/details/6541531

 

 

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.