Académique Documents
Professionnel Documents
Culture Documents
http://www.mkyong.com/android/android-webview-example/
Java Forum
Advertise
Contact Us
RSS
Java Core
Web Frameworks
Spring
Hibernate
Web Service
Others...
Search
Androids WebView allows you to open an own windows for viewing URL or custom html markup page. In this tutorial, you will create two pages, a page with a single button, when you clicked on it, it will navigate to another page and display URL google.com in WebView component.
Live Demo Try your AJAX code online! Demo -> ZK Explorer Zkoss.org Really Cool JSF DataTable Video Tutorials, Demos & Examples Free Download & more www.simplica.com Integrate Java and C++ Easy, professional solution for all your Java-C++ integration projects.
www.CodeMesh.com
P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3.
Sukhmeet
Satish
Sameh
Anand
Santhosh
File : res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/buttonUrl" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Go to http://www.google.com" /> </LinearLayout>
Mohammad
Hassan
Ramesh
Sneha
Mohamed
2. Activity
Two activity classes, an activity to display a button, another activity display the WebView with predefined URL. File : MainActivity.java
package com.mkyong.android; import import import import import android.app.Activity; android.content.Context; android.content.Intent; android.os.Bundle; android.view.View;
1 de 7
27/02/12 17:03
http://www.mkyong.com/android/android-webview-example/
@Override public void onClick(View arg0) { Intent intent = new Intent(context, WebViewActivity.class); startActivity(intent); } }); } }
File : WebViewActivity.java
package com.mkyong.android; import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; public class WebViewActivity extends Activity { private WebView webView; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview); webView = (WebView) findViewById(R.id.webView1); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl("http://www.google.com"); } }
Subscribe
Latest Posts
Android WebView example
3. Android Manifest
WebView required INTERNET permission, add below into AndroidManifest.xml.
<uses-permission android:name="android.permission.INTERNET" />
Android TabLayout example How to import class automatically in Eclipse How to remove unused imports in Eclipse Android GridView example How to display line numbers in Eclipse How to check if Date is within a certain range in Java? How to check if date is valid in Java Struts 2 dynamic image example try-with-resources example in JDK 7
Advertisement
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".WebViewActivity" android:theme="@android:style/Theme.NoTitleBar" /> <activity android:label="@string/app_name" android:name=".MainActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
As a market leader in the reseller hosting industry, micfo.com offers you a great opportunity to start your own web hosting company. Join them today.
Latest Comments
Navin on JSON example with Jersey + Jackson
2 de 7
27/02/12 17:03
http://www.mkyong.com/android/android-webview-example/
How to write a service consuming a JSON string as a parameter. I mean, method should consume directl... Meethas on Maven + (Spring + Hibernate) Annotation + MySql Example
4. Demo
By default, just display a button.
Hi , I need a simple hibernate project without maven or ant and i need to run it in apache tomcat se... HibLearner on Hibernate fetching strategies examples Suppose I have an Order table with 50 columns and I have an Order class with 50 properties and mappe... mkyong on Connect to PostgreSQL with JDBC driver Make sure postgresql-9.1-901.jdbc3.jar is configured correctly and able to locate in your class path... mkyong on Struts 2 Hello World Example Not really related with above article, please post your question on JavaNullPointer.com? And elabora...
5. Demo, Again
WebView allow you to manually load custom HTML markup, via webView.loadData(), see modified version :
package com.mkyong.android; import android.app.Activity;
3 de 7
27/02/12 17:03
http://www.mkyong.com/android/android-webview-example/
References
1. Official Android webView example 2. Android WebView Javadoc 3. Switching Android activity
4 de 7
27/02/12 17:03
http://www.mkyong.com/android/android-webview-example/
To Whom It May Concern, If you have any Java questions or problems, please post at this new JavaNullPointer.com forum. Best Regards, mkyong
Related Posts
Android TabLayout example Android GridView example Android ListView example How to set default activity for Android application Attach Android source code to Eclipse IDE
Popular Posts
Top 5 free Java eBooks Top 8 Java people you should know Top 20 Java websites you must visit Top 10 Java regular expression examples Top 10 open source forums in collection Top 5 open source Q&A systems
Leave a Reply
Name (required)
Website
[Note] - To post source code in comment, wrap your source code like this :
1. Java - <pre lang="java"> Java codes here </pre> 2. XML - <pre lang="xml"> XML here </pre> 3. HTML - <pre lang="html4strict"> HTML here </pre>
5 de 7
27/02/12 17:03
http://www.mkyong.com/android/android-webview-example/
Submit Comment
Notify me of followup comments via e-mail
Vote
Favorites Links
DZone - Fresh Links Official Java EE 5 Tutorial Spring 2.5.x documentation Hibernate core documentation Java SE 6.0 API documentation Java EE 6.0 API documentation Java Secure Socket Extension (JSSE) Reference Guide JSP home page JSF home page Eclipse IDE for Java developer Maven home page Ant home page Struts 1.3 documentation Struts 2.2 documentation Maven central repository Java.Net Maven repository Martin Fowler
About Mkyong.com
Mkyong.com is about a person who is facing the big tree (Java web development), always wonder why the tree (Java) is so big!
All tutorials and examples are unique, and from my personal experience, if you find mistake in my tutorial, please correct me :) after all, we learned through the process. For Java question that is not related to the tutorial, you can post here - Java Q&A forum. 1. Twitter - Follow Me 2. Facebook - Fan Page 3. RSS - Subscribe It Advertise With Us
6 de 7
27/02/12 17:03
http://www.mkyong.com/android/android-webview-example/
7 de 7
27/02/12 17:03