Development of a simple Web browser for android

Source: Internet
Author: User

Development of a simple Web browser for android
Feature Overview:
1. Use the WebView control to develop a simple browser
2. implemented a simple Web browser function.
3. Be able to browse all content on the webpage. However, video playback is not supported.
4. Fast browser loading.
:

Programming highlights:
1. Use the WebView Control for web page display
2. Set WebView attributes to support more functions.
3. When a user clicks a link on a webpage, the user still uses the webpage to load
4. Set permissions to enable the app to access the Internet.
5. Activity layout.
[Java] code

[Java]
Package com. example. njupt. zhb. zhbwebbrowser;
 
 
Import android. OS. Bundle;
Import android. annotation. SuppressLint;
Import android. app. Activity;
Import android. content. Intent;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. webkit. WebView;
Import android. webkit. WebViewClient;
Import android. widget. Button;
Import android. widget. EditText;
Import android. widget. TextView;
/*
* @ Author: ZhengHaibo
* Web: blog.csdn.net/nuptboyzhb
* Mail: zhb931706659@126.com
* 2012-8-31 Nanjing njupt
*/
Public class WebBrowser extends Activity implements OnClickListener {
EditText url;
TextView mTitle;
WebView mWebView;
Button goButton;
Button backButton;
Button aboutButton;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_web_browser );
SetTitle ("WebBrowser Made by Zhenghaibo ");
SetControl ();
SetWebStyle ();
}
Private void setControl (){
Url = (EditText) findViewById (R. id. urltext );
MWebView = (WebView) findViewById (R. id. webshow );
GoButton = (Button) findViewById (R. id. GoBtn );
BackButton = (Button) findViewById (R. id. BackBtn );
AboutButton = (Button) findViewById (R. id. AboutBtn );
MTitle = (TextView) findViewById (R. id. WebTitle );
GoButton. setOnClickListener (this );
BackButton. setOnClickListener (this );
AboutButton. setOnClickListener (this );
}
@ SuppressLint ("SetJavaScriptEnabled ")
Private void setWebStyle (){
MWebView. getSettings (). setJavaScriptEnabled (true );
MWebView. getSettings (). setsuppzoom zoom (true );
MWebView. setScrollBarStyle (WebView. SCROLLBARS_OUTSIDE_OVERLAY );
MWebView. requestFocus ();
MWebView. loadUrl ("http://blog.csdn.net/nuptboyzhb ");
MWebView. setWebViewClient (new MyWebViewClient ());
}
@ Override
Public void onClick (View v ){
// TODO Auto-generated method stub
Switch (v. getId ()){
Case R. id. GoBtn:
String url_text;
String url_head = "http ://";
Url_text = url. getText (). toString ();
If (! Url_text.contains ("http ://")){
Url_text = url_head.concat (url_text );

}
MWebView. loadUrl (url_text );
MTitle. setText ("you are browsing web:" + url_text );
Break;
Case R. id. BackBtn:
MWebView. goBack ();
Break;
Case R. id. AboutBtn:
Intent intent = new Intent (this, ActivityAbout. class );
StartActivity (intent );
Break;
}
}
Class MyWebViewClient extends WebViewClient {
@ Override
Public boolean shouldOverrideUrlLoading (WebView view, String url _){
View. loadUrl (url _);
Url. setText (url _);
MTitle. setText ("you are browsing web:" + url _);
Return true;
}
}
}

Related Article

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.