File main. java
Copy codeThe Code is 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 when the activity is first created .*/
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 codeThe Code is 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 codeThe Code is as follows: <android: layout_height = "wrap_content"
Android: baselineAligned = "false">
<Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content">
The configuration file AndroidManifest. xml needs to be set