CSDN簡單安卓用戶端實現,csdn安卓用戶端
一直是在電腦上面看CSDN的部落格、資訊,今天做了個小軟體在手機上面查看資訊和部落格。
直接上代碼:
一、首先是歡迎介面 -- 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);}}
其布局檔案很簡單--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>
二、首頁面--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 isExit = false;Timer tExit = new 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) {// 根據傳入的參數再去載入新的網頁view.loadUrl(url);// 表示當前WebView可以處理開啟新網頁的請求,不用藉助系統瀏覽器return true;}@Overridepublic void onReceivedError(WebView view, int errorCode,String description, String failingUrl) {super.onReceivedError(view, errorCode, description, failingUrl);Toast.makeText(ShowActivity.this, "呃!載入失敗,也許斷網了,或者不能訪問!",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 true;}return super.onKeyDown(keyCode, event);}@Overridepublic void onBackPressed() {if (isExit == false) {isExit = true;Toast.makeText(this, "再按一次返回鍵回到案頭", 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);// 添加四個功能表項目menu.add(Menu.NONE, Menu.FIRST + 1, 1, "協助").setIcon(R.drawable.menu_help);menu.add(Menu.NONE, Menu.FIRST + 2, 2, "退出").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("退出").setMessage("你確定要退出CSDN嗎?").setIcon(android.R.drawable.ic_dialog_info).setPositiveButton(R.string.ok,new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog,int whichButton) {finish();// 退出程式}}).setNegativeButton(R.string.cancel, null).show();return true;}return false;}}
布局檔案--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>
三、協助頁面--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);}}
布局檔案--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="第一步:" android:textSize="23sp" /> <TextView android:layout_width="100dp" android:layout_height="match_parent" android:layout_marginRight="5dp" android:layout_marginLeft="5dp" android:text="第二步:" android:textSize="23sp" /> <TextView android:layout_width="100dp" android:layout_height="match_parent" android:layout_marginRight="10dp" android:text="第三步:" 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="右上方表徵圖" android:textSize="15sp" /> <TextView android:layout_width="100dp" android:layout_height="match_parent" android:layout_marginRight="5dp" android:layout_marginLeft="5dp" android:text="點擊部落格" android:textSize="15sp" /> <TextView android:layout_width="100dp" android:layout_height="match_parent" android:layout_marginRight="10dp" android:text="點擊登入" 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>
四、最後別忘了在AndroidManifest.xml檔案中添加訪問網路的許可權
<uses-permission android:name="android.permission.INTERNET" />
五、Apk:http://download.csdn.net/detail/xdwyyan/8121301
android簡單開發
給你個傳送門吧,不知道會不會被河蟹。。。
www.eoeandroid.com/thread-308155-1-1.html
CSDN安卓用戶端最上方導覽列四個字是什
"全部文檔"