1 / 47

Ch2 初探 Android 程式開發

Ch2 初探 Android 程式開發. 一、 建立一個簡單的應用程式專案 (2-1). 啟動 Eclipse 。 執行「 File>New>Android Application Project 」選項 。 設定專案相關資訊 。 設定專案架構 。 設定專案圖示 。 選擇要建立的活動 (Activity) 類型 。 設定活動內容. 啟動 Eclipse. 啟動 Eclipse. 執行「 File>New>Android Application Project 」選項. 設定專案相關資訊 (1). 設定專案相關資訊 (2). 設定專案架構. 設定專案圖示.

diep
Download Presentation

Ch2 初探 Android 程式開發

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Ch2 初探Android程式開發

  2. 一、建立一個簡單的應用程式專案(2-1) • 啟動Eclipse 。 • 執行「File>New>Android Application Project」選項。 • 設定專案相關資訊。 • 設定專案架構。 • 設定專案圖示。 • 選擇要建立的活動(Activity)類型。 • 設定活動內容

  3. 啟動Eclipse

  4. 啟動Eclipse

  5. 執行「File>New>Android Application Project」選項

  6. 設定專案相關資訊(1)

  7. 設定專案相關資訊(2)

  8. 設定專案架構

  9. 設定專案圖示

  10. 選擇要建立的活動(Activity)類型

  11. 設定活動內容

  12. 完成的專案初稿

  13. 載入Android SDK、應用程式佈局及其他設定)

  14. 修改Android Target 版本 • 右擊專案檔名 • 選Properities/Android • 選擇適當版本

  15. 二、模擬器設定 • 從Eclipse執行「Window>Android Virtual Device Manager」。 • 按右上角的「New」鈕,以建立一個新的AVD。 • 設定AVD參數。 • 將新建的AVD增至對話框的AVD清單中。

  16. 建立之AVD清單

  17. 三、以AVD測試應用程式專案(2-1) • 開啟「Android Virtual Device Manager」對話框。 • 選要使用的AVD,按「Start」鈕啟動AVD 。 • 按「Lunch」鈕關閉對話框並載入此AVD 。 • Eclipse IDE開始模擬此AVD 。 • 模擬裝置完成載入,以滑鼠敲「OK」鈕啟動此模擬裝置。 • 關閉「Android Virtual Device Manager」對話框。

  18. AVD版本需大於專案之Android版本,才能執行

  19. 建立AVD且彈出視窗後,須將後端之屬性是窗關閉,方能使用Eclipse之Run/Run as configuration

  20. 三、以AVD測試應用程式專案(2-2) • 從Eclipse主畫面左面板選應用程式專案,再按工具列上的「Run Activity_main.xml」工具鈕。 • 從開啟的「Run AS」對話框中選「Android Application」,然後按「OK」鈕。 • 以滑鼠按模擬裝置的電源鈕,模擬將裝置關電。

  21. 選取專案

  22. 選取模擬AVD

  23. 測試結果

  24. 解除安裝應用程式先按 Home, 再按 Menu

  25. 捲選應用程式

  26. 先按 Forcestop , 再按 Uninstall

  27. 四、以實體裝置測試應用程式專案 • 啟動實體裝置的「USB除錯」功能。 • 透過USB將實體裝置連至執行Eclipse的電腦。 • 從Eclipse主畫面左面板選應用程式專案,再執行「Run>Run As>1.Android Application」選項。 • 從開啟的「Android Device Chooser」對話框,先選「Choose a running Android device」(連至電腦執行中的實體裝置),然後從顯示的清單中點選你的實體裝置。

  28. 安裝USB驅動程式說明 • http://www.sogi.com.tw/mobile/articles/6090212-%E4%B8%8B%E8%BC%89%E4%B8%A6%E5%AE%89%E8%A3%9D+Android+USB+%E9%A9%85%E5%8B%95%E7%A8%8B%E5%BC%8F

  29. 在實體裝置上測試 • 於手機上點擊 [設定] • 點選[開發人員選項] • 點選[USB偵錯] • ?允許USB偵錯嗎?[確定]

  30. 仿AVD 步驟執行專案

  31. 選取連線之實體裝置

  32. 五、Android專案架構剖析(2-1) • src:此資料夾用以存放原始程式檔。 • gen:存放ADT自動產生的java程式檔的資料夾,其中最重要的就是R.java,R.java內建立一個R類別,此類別為res資料夾中的每一個資源指定了唯一的ID,程式透過這ID就可引用它對應的資源。 • assets:此資料夾預設是空的,你可以在這裡放置一些原始檔案。

  33. 五、Android專案架構剖析(2-2) • bin:專案建置後產生的輸出資料夾,包括了應用程式建置後的安裝封包.apk檔,及其他編譯過(compiled)的資源。 • libs:用以存放私有的函式庫檔案的資料夾。 • res:用以存放應用程式專案所需要資源的資料夾。 • AndroidManifest.xml:專案的組態檔。 • Project.properties:此檔案包含了專案的設定。

  34. Android Manifest.xml檔案 • <?xml version="1.0" encoding="utf-8"?> • <manifest xmlns:android="http://schemas.android.com/apk/res/android" • package="com.example.newtest" • android:versionCode="1" • android:versionName="1.0" > • <uses-sdk • android:minSdkVersion="8" • android:targetSdkVersion="18" /> • <application • android:allowBackup="true" • android:icon="@drawable/ic_launcher" • android:label="@string/app_name" • android:theme="@style/AppTheme" > • <activity • android:name="com.example.newtest.MainActivity" • android:label="@string/app_name" > • <intent-filter> • <action android:name="android.intent.action.MAIN" /> • <category android:name="android.intent.category.LAUNCHER" /> • </intent-filter> • </activity> • </application> • </manifest>

  35. MainActivity.java • package com.example.newtest; • import android.os.Bundle; • import android.app.Activity; • import android.view.Menu; • public class MainActivity extends Activity { • @Override • protected void onCreate(Bundle savedInstanceState) { • super.onCreate(savedInstanceState); • setContentView(R.layout.activity_main); • } • @Override • public boolean onCreateOptionsMenu(Menu menu) { • // Inflate the menu; this adds items to the action bar if it is present. • getMenuInflater().inflate(R.menu.main, menu); • return true; • } • }

  36. Graphical Layout

  37. Activity_main.xml檔 • <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" • xmlns:tools="http://schemas.android.com/tools" • android:layout_width="match_parent" • android:layout_height="match_parent" • android:paddingBottom="@dimen/activity_vertical_margin" • android:paddingLeft="@dimen/activity_horizontal_margin" • android:paddingRight="@dimen/activity_horizontal_margin" • android:paddingTop="@dimen/activity_vertical_margin" • tools:context=".MainActivity" > • <TextView • android:layout_width="wrap_content" • android:layout_height="wrap_content" • android:text="@string/hello_world" /> • </RelativeLayout>

  38. Strings.xml 編輯API

  39. Strings.xml檔案 • <?xml version="1.0" encoding="utf-8"?> • <resources> • <string name="app_name">newTest</string> • <string name="action_settings">Settings</string> • <string name="hello_world">Hello world!</string> • </resources>

  40. Sample Code • Import the sample project: • Select File > New > Other > Android Sample Project and click Next. • Select the latest version of the Android SDK and click Next. • Scroll down the list of samples and select Maps [Google Play Services]. => Example • Click Finish. • https://developers.google.com/maps/documentation/android/intro?hl=zh-TW

More Related