
Create a New Android Application:
- Project Name: AndroidBrowser
- Application Name: Android Browser
- Package Name: com.exercise.AndroidBrowser
- Create Activity: AndroidBrowser
- Min SDK Version: 3
Modify main.xml to have a WebView:
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
Modify AndroidBrowser.java
package com.exercise.AndroidBrowser;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class AndroidBrowser extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String myURL = "http://picturedmagazine.blogspot.com";
WebView myBrowser=(WebView)findViewById(R.id.mybrowser);
/*By default Javascript is turned off,
* it can be enabled by this line.
*/
myBrowser.getSettings().setJavaScriptEnabled(true);
myBrowser.loadUrl(myURL);
}
}
You also have make change on AndroidManifest.xml, so your application can access internet:
package="com.exercise.AndroidBrowser"
android:versionCode="1"
android:versionName="1.0">
android:label="@string/app_name">
Next article >>
- AndroidBrowser, with simple navigating functions
- Load local HTML webpage inside APK

0 تعليقات