Course Content

If you are facing any issue in playing video please use Firefox browser.

Course Content

Description

Creating WebView Application

 

Now in this video we are going to create a webView application in which we will load Google page.

First of all we will design the layout of our application. In main.xml file we have take one simple linear layout and a button. And in webview.xml file we are creating a WebView providing with basic height and width.

After that in its manifest file AndroidManifest.xml we need to provide one permission ie.,

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

Now we will code inside the Java file where we have two different activities, one is MainActivity.java and other one is WebViewActivity.java.

Now inside our WebViewActivity.java file we will code the following,

public class WebViewActivity extends Activity

{

private WebView webView;

public void onCreate (Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.webview);

webView.findViewById(R.id.webView1);

webView.getSettings().getJavaScriptEnabled(true);

webView.loadUrl("http://www.google.com");

String customHtml="<html><body><h1>Hello, WebView</h1></body></html>";

webView.loadData(customHtml,"text/html","UTF-8");

}

Now inside our MainActivity.java file we will code the following,

button=(Button)findViewById(R.id.buttonUrl);

button.setOnClickListener(new onClickListener()

{

@Override

public void onClick(View arg0)

{

Intent intent=new Intent(context,WebViewActivity.class);

startActivity(intent);

}

};

Now we will execute our code. When we execute our code a button of Google page link appears, when we click on it if Internet is available to the emulator, google page will get load. But in case of no Internet availability, the simple text 'Hello WebView' appears in front of our screen.

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download The Apps

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
297K+ Downloads
App Download Section Circle 1
4.5 Rating
App Download Section Circle 2
10K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere