CSDN Simple Android Client Development

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);}}
The layout file is simple--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/imageview1" 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 Web page view.loadurl (URL) According to the parameters passed in;// 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, may have broken the network, or could not access! ", 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"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Wrap_content "android:layout_height=" wrap_content "android:orientation=" vertical " > <linearlayout android:layout_width= "wrap_content" android:layout_height= "Wrap_content" and roid:orientation= "Horizontal" > <textview android:id= "@+id/imageview1" Android:layout_w Idth= "100DP" android:layout_height= "match_parent" android:layout_marginright= "10DP" Andro            id:text= "First step:" Android:textsize= "23sp"/> <textview android:id= "@+id/imageview1" Android:layout_width= "100DP" android:layout_height= "Match_parent" android:layout_marginright= "5        DP "android:layout_marginleft=" 5DP "android:text=" Step Two: "android:textsize=" 23sp "/> <textview Android: id= "@+id/imageview1" android:layout_width= "100DP" android:layout_height= "Match_parent" a ndroid:layout_marginright= "10DP" android:text= "Step Three:" android:textsize= "23sp"/> </linearlay        out> <linearlayout android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:orientation= "Horizontal" android:layout_margintop= "10DP" > <textview android:i D= "@+id/imageview1" android:layout_width= "100DP" android:layout_height= "Match_parent" and roid:layout_marginright= "10DP" android:text= "click on the top right corner icon" android:textsize= "15sp"/> <textv Iew android:id= "@+id/imageview1" android:layout_width= "100DP" android:layout_height= "MATC H_parent "android:layout_marginright=" 5DP "android:layout_marginleft=" 5DP "android:text=" Click on the Blog "Android: textsize= "15sp"/> <textview android:id= "@+id/imageview1" android:layout_width= "100DP" android:layout_height= "Match_parent" android:layout_marginright= "10DP" android:text= "click to login "Android:textsize=" 15sp "/> </LinearLayout> <linearlayout android:layout_width=" wrap            _content "android:layout_height=" wrap_content "android:orientation=" Horizontal "> <imageview Android:id= "@+id/imageview1" android:layout_width= "100DP" android:layout_height= "Match_pare            NT "android:layout_marginright=" 10DP "android:src=" @drawable/first "/> <imageview             Android:id= "@+id/imageview1" android:layout_width= "100DP" android:layout_height= "Match_parent" android:layout_marginleft= "5DP" android:layout_marginright= "5DP" android:src= "@drawable/ Second "/> < ImageView android:id= "@+id/imageview1" android:layout_width= "100DP" Android:layout_heigh t= "Match_parent" android:layout_marginleft= "10DP" android:src= "@drawable/third"/> </linear Layout></linearlayout>
Iv. Finally, don't forget to add access to the network in the Androidmanifest.xml file

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



CSDN Simple Android Client Development

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.