Csdn Simple Android Client implementation

Source: Internet
Author: User

has been on the computer to see CSDN blog, information, today made a small software on the phone to view information and blog.


Directly on the code:

First, the Welcome interface--Loadingactivity.java

Package Com.example.webviewtest;import Android.app.activity;import Android.content.intent;import android.os.Bundle ; Import Android.os.handler;import Android.view.window;public class Loadingactivity extends activity{@ overrideprotected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate ( Savedinstancestate); requestwindowfeature (Window.feature_no_title); Setcontentview (R.layout.loading); new Handler ( ). postdelayed (New Runnable () {@Overridepublic void run () {Intent mainintent = new Intent (Loadingactivity.this, Showactivity.class); startactivity (mainintent); Finish ();}}, 2000);}}
its layout file is very easy--loading.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent "    android:o rientation= "vertical" >    <imageview        android:id= "@+id/imageview" android:layout_width= "Wrap_        Content "        android:layout_height=" fill_parent "        android:src=" @drawable/splash "/></linearlayout>

second, the main page surface--showactivity.java
Package Com.example.webviewtest;import Java.util.timer;import Java.util.timertask;import Android.annotation.suppresslint;import Android.app.activity;import Android.app.alertdialog;import Android.content.dialoginterface;import Android.content.intent;import Android.os.bundle;import Android.view.keyevent;import Android.view.menu;import Android.view.menuitem;import Android.view.Window;import Android.webkit.websettings.renderpriority;import Android.webkit.webview;import android.webkit.WebViewClient; Import Android.widget.toast;public class Showactivity extends Activity {private WebView webview;private static Boolean is Exit = false; Timer texit = new timer ();//Timer timertask task; @SuppressLint ("setjavascriptenabled") @Overrideprotected void OnCreate ( Bundle savedinstancestate) {super.oncreate (savedinstancestate); Requestwindowfeature (Window.feature_no_title); Setcontentview (r.layout.activity_main); WebView = (WebView) Findviewbyid (R.id.web_view); Webview.getsettings (). Setbuiltinzoomcontrols (true); webView.getsettings (). Setjavascriptenabled (True); Webview.getsettings (). setrenderpriority (Renderpriority.high);// Webview.getsettings (). Setblocknetworkimage (True); Webview.setwebviewclient (new Webviewclient () {@Overridepublic Boolean shouldoverrideurlloading (WebView view, String URL) {//To load new page view.loadurl (URL) According to the passed-in argument;// Indicates that the current webview can handle a request to open a new webpage without using the System browser to return true; @Overridepublic void Onreceivederror (WebView view, int errorcode,string description, String failingurl) { Super.onreceivederror (view, ErrorCode, description, Failingurl); Toast.maketext (Showactivity.this, "Uh! Failed to load, maybe off the net. Or not! ", Toast.length_long). Show ();}}); Webview.loadurl ("http://www.csdn.net/");} @Overridepublic boolean onKeyDown (int keycode, keyevent event) {if (keycode = = Keyevent.keycode_back && webview.c Angoback ()) {webview.goback ();//Return to the previous page return true;} Return Super.onkeydown (KeyCode, event);} @Overridepublic void onbackpressed () {if (Isexit = = False) {Isexit = true; Toast.maketext (This, "press the Back button again to return to the desktop", Toast.length_Short). Show (); task = new TimerTask () {@Overridepublic void run () {isexit = false;}}; Texit.schedule (Task, 2000);} else {finish (); System.exit (0);}} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//TODO auto-generated method Stubsuper.oncreateoptionsmenu ( menu);//Add four menu items menu.add (menu.none, Menu.first + 1, 1, "help"). SetIcon (R.drawable.menu_help); Menu.add (Menu.none, Menu.first + 2, 2, "exit"). SetIcon (R.drawable.menu_quit); return true;} @Overridepublic boolean onoptionsitemselected (MenuItem Item) {//TODO auto-generated method Stubswitch (Item.getitemid ( ) {case Menu.first + 1:intent Intent = new Intent (showactivity.this, Helpactivity.class); startactivity (Intent); return True;case Menu.first + 2:new Alertdialog.builder (this). Settitle ("Exit"). Setmessage ("Are you sure you want to exit Csdn?"). "). SetIcon (Android. R.drawable.ic_dialog_info). Setpositivebutton (R.string.ok,new Dialoginterface.onclicklistener () {public void OnClick (dialoginterface dialog,int whichbutton) {finish ();//Exit Program}}). Setnegativebutton (r.string.canceL, NULL). Show (); return true;} return false;}}
Layout file--activity_main.xml
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    android:layout_width= "Match_ Parent "    android:layout_height=" match_parent ">    <webview        android:id=" @+id/web_view "        Android:layout_width= "Match_parent"        android:layout_height= "Match_parent"/></linearlayout>

third, help page--helpactivity.java

Package Com.example.webviewtest;import Android.app.activity;import Android.os.bundle;import Android.view.Window; public class Helpactivity extends activity{@Overrideprotected void OnCreate (Bundle savedinstancestate) {//TODO Auto-generated method Stubsuper.oncreate (savedinstancestate); Requestwindowfeature (Window.feature_no_title); Setcontentview (R.LAYOUT.HELP);}}
Layout file--help.xml

<?xml version= "1.0" encoding= "Utf-8"?

><tablelayout xmlns:android= "Http://schemas.android.com/apk/res/android"     android:layout_ Width= "Fill_parent"     android:layout_height= "Wrap_content"     android: stretchcolumns= "0,1,2" >    <TableRow>        < textview            android:layout_width= "100DP"              android:layout_height= "Match_parent"              android:layout_marginright= "10DP"              android:text= "First step:"              android:textsize= "23SP"/>        <textview             android:layout_width= "100DP"              android:layout_height= "Match_parent"              android:layout_marginright= "5DP"              android:layout_marginleft= "5DP"             Android : text= "Second step:"             android:textsize= "23sp"/>         <TextView             android:layout_width= "100DP"             android:layout_height= "Match_parent"             android: layout_marginright= "10DP"             android:text= "step Three:"             android:textsize= "23SP"/>     </tablerow>    <TableRow        android:layout_margintop= "20DP" >       <TextView             android:layout_width= "100DP"              android:layout_height= "Match_parent"             android:layout_marginright= "10DP"             android: text= "upper right corner icon"             android:textsize= "15sp"/>         <TextView             android:layout_width= "100DP"             android:layout_height= "Match_parent"             android: Layout_marginright= "5DP "            android:layout_marginleft=" 5DP "             android:text= "click blog"              android:textsize= "15SP"/>        < textview            android:layout_width= "100DP"              android:layout_height= "Match_parent"              android:layout_marginright= "10DP"              android:text= "Click to sign In"              android:textsize= "15SP"/>    </TableRow>    < tablerow>        <ImageView             android:layout_width= "100DP"             android:layout_height= "Match_parent"             android: layout_marginright= "10DP"             android:src= "@ Drawable/first "/>        <ImageView             android:layout_width= "100DP"              android:layout_height= "Match_parent"              android:layout_marginleft= "5DP"              android:layout_marginright= "5DP"             android:src= "@drawable/second"/>        <ImageView             android:layout_width= "100DP"              android:layout_height= "Match_parent"             android:layout_marginleft= "10DP"             android:src= "@drawable/third"/>    </TableRow></TableLayout>

Iv. Finally, don't forget to add access to the network in the Androidmanifest.xml file .

<uses-permission android:name= "Android.permission.INTERNET"/>


Wu, apk:http://download.csdn.net/detail/xdwyyan/8121301



Csdn Simple Android Client implementation

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.