A View that displays the web pages
res/layout/webview.xml
Step 1: webview.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="@+id/web"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Step 2: WebView.java :
public class WebView extends Activity {
WebView browser;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
browser=(WebView)findViewById(R.id.web);
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setUseWideViewPort(true);
browser.getSettings().setDefaultFontSize(20);
// browser.loadUrl("http://www.google.com");
browser.loadUrl("file:///android_asset/hello.html");
}
}
Step 3: Place the hello.html in assets
Step 4: Add internet permission to manifest file :
<uses-permission android:name="android.permission.INTERNET" />
res/layout/webview.xml
Step 1: webview.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="@+id/web"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Step 2: WebView.java :
public class WebView extends Activity {
WebView browser;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
browser=(WebView)findViewById(R.id.web);
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setUseWideViewPort(true);
browser.getSettings().setDefaultFontSize(20);
// browser.loadUrl("http://www.google.com");
browser.loadUrl("file:///android_asset/hello.html");
}
}
Step 3: Place the hello.html in assets
Step 4: Add internet permission to manifest file :
<uses-permission android:name="android.permission.INTERNET" />
No comments:
Post a Comment