Minibrowser.java
public class Minibrowser extends Activity {EditText URL; WebView Showwebview; Button SearchButton; String urlstr = null, @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main); url = (EditText) Findviewbyid (r.id.url); Showwebview = (WebView) Findviewbyid (r.id.show ); SearchButton = (Button) Findviewbyid (R.id.searchbutton);//real-time test, guaranteed on the current Activity display page, Instead of your own browser, display showwebview.setwebviewclient (new Webviewclient () {@Overridepublic Boolean shouldoverrideurlloading ( WebView view, String URL) {//TODO auto-generated Method stub//load page view.loadurl (URL) with WebView; return true;}); /enable JavaScript showwebview.getsettings (). Setjavascriptenabled (True); Searchbutton.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View v) {//TODO auto-generated Method stuburlstr = Url.gettext (). Tostrin g (); Showwebview.loadurl (URLSTR);}}); @Overridepublic boolean onKeyDown (int keycode, keyevent event) {//TODO auto-generated Method stub//PressThe BACKSPACE key can be skipped to the upper page if (keycode = = Keyevent.keycode_back) {showwebview.goback (); return true;} Return Super.onkeydown (KeyCode, event);}}
Mail.xml Layout file
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" wrap_content "android:layout_height=" Match_parent "Tools:context =". Minibrowser "> <edittext android:id=" @+id/url "android:layout_width=" Fill_parent "android:l ayout_height= "Wrap_content" android:layout_alignparentleft= "true" android:singleline= "true" android:l ayout_toleftof= "@+id/searchbutton" android:layout_aligntop= "@+id/searchbutton" android:layout_alignbottom= "@ +id/searchbutton "/> <button android:id=" @+id/searchbutton "android:layout_width=" Wrap_content " android:layout_height= "Wrap_content" android:layout_alignparentright= "true" android:text= "@string/search "/> <webview android:id=" @+id/show "android:layout_width=" fill_parent "android:layout_height=" Fill_pare NT "android:layout_below=" @id/searchbuTton "/> </RelativeLayout>
Manife file settings allow Internet access
<uses-permission android:name= "Android.permission.INTERNET"/>
Test results on the real machine
Mini Browser--webview Learning