File Main.java
Copy Code code as follows:
Package com. hhbrowser.android;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.os.Handler;
Import Android.util.Log;
Import Android.view.View;
Import Android.webkit.WebView;
Import android.webkit.WebViewClient;
Import Android.widget.Button;
Import Android.widget.EditText;
public class Main extends activity {
/** called the activity is a. */
WebView WV;
Handler Handler;
Button Btnbutton;
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
WV = (WebView) Findviewbyid (R.ID.WEBVIEW1);
Wv.getsettings (). Setjavascriptenabled (True);
Wv.setscrollbarstyle (0);
Wv.loadurl ("http://www.baidu.com");
Btnbutton = (Button) Findviewbyid (R.id.turn);
Btnbutton.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
EditText EditText = (edittext) Findviewbyid (R.ID.EDITTEXT1);
String strURL = string.valueof (Edittext.gettext ());
if (Strurl.contains ("http://"))
{
LOG.V ("TTT", strURL);
Loadurl (Wv,strurl);
}else {
LOG.V ("TTT", strURL);
Loadurl (WV, "http://www.baidu.com");
}
}
});
Wv.setwebviewclient (New Webviewclient ()
{
Public boolean shouldoverrideurlloading (final WebView view, final String URL) {
EditText NewText = (edittext) Findviewbyid (R.ID.EDITTEXT1);
Newtext.settext (URL);
Loadurl (View,url);
return true;
}
});
}
public void Loadurl (final webview view,final String URL) {
New Thread () {
public void Run () {
View.loadurl (URL);
}
}.start ();
}
}
2 Layout file Main.xml
Copy Code code as follows:
android:orientation= "Vertical"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
>
<android:layout_height= "Wrap_content"
Android:baselinealigned= "false" >
<android:text= ""
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:id= "@+id/edittext1"
android:maxems= "15"
Android:minems= "10"
Android:layout_gravity= "Center_vertical"
>
Android:id= "@+id/turn"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" >
Copy Code code as follows:
<android:layout_height= "Wrap_content"
Android:baselinealigned= "false" >
<android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content" >
Configuration file Androidmanifest.xml need to be set inside