CSDN is implemented by simple Android clients and csdn Android clients

Source: Internet
Author: User

CSDN is implemented by simple Android clients and csdn Android clients

I have been reading CSDN blogs and information on my computer. Today I have made a small software program to view information and blogs on my mobile phone.


Directly run the Code:

I. 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:orientation="vertical" >    <ImageView        android:id="@+id/imageView"        android:layout_width="wrap_content"        android:layout_height="fill_parent"        android:src="@drawable/splash" /></LinearLayout>

2. Home Page -- 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. we Bkit. 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 isExit = false; Timer tExit = new Timer (); // Timer TimerTask task; @ SuppressLint ("SetJavaScriptEnabled ") @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedIns TanceState); 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) {// load the new webpage view based on the input parameters. loadUrl (url); // indicates that the current WebView can process requests for opening a new webpage. You do not need to use 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, "er! Loading failed. The network may be disconnected or cannot be accessed! ", Toast. LENGTH_LONG ). show () ;}}); webView. loadUrl ("http://www.csdn.net/") ;}@ Overridepublic boolean onKeyDown (int keyCode, KeyEvent event) {if (keyCode = KeyEvent. KEYCODE_BACK & webView. canGoBack () {webView. goBack (); // return the previous page return true;} return super. onKeyDown (keyCode, event) ;}@ Overridepublic void onBackPressed () {if (isExit = false) {isExit = true; Toast. makeText (this, "press the return key 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. add (Menu. NONE, Menu. FIRST + 1, 1, "help "). setIcon (R. drawable. menu_help); menu. add (Menu. NONE, Menu. FIRST + 2, 2, "quit "). se TIcon (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 ("quit "). 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 Diener, 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>

3. 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 = ", 2"> <TableRow> <TextView android: layout_width = "100dp" android: layout_height = "match_parent" android: layout_marginRight = "10dp" android: text = "Step 1:" android: textSize = "23sp"/> <TextView android: layout_width = "100dp" android: layout_height = "match_parent" android: layout_marginRight = "5dp" android: layout_marginLeft = "5dp" android: text = "Step 2:" android: textSize = "23sp"/> <TextView android: layout_width = "100dp" android: layout_height = "match_parent" android: layout_marginRight = "10dp" android: text = "Step 3:" 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 = "icon in the upper right corner" 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 log on" android: textSize = "15sp"/> </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>
4. Do not forget to add the network access permission to the AndroidManifest. xml file.

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


5. Apk: http://download.csdn.net/detail/xdwyyan/8121301




Simple android Development

Let me give you a portal. I don't know if it will be attacked...
Www.eoeandroid.com/thread-308155-1-1.html

Which of the following is the top navigation bar of the CSDN Android client?

"All documents"

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.