Mini Browser--webview Learning

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.