Upload
diep
View
60
Download
0
Embed Size (px)
DESCRIPTION
Ch2 初探 Android 程式開發. 一、 建立一個簡單的應用程式專案 (2-1). 啟動 Eclipse 。 執行「 File>New>Android Application Project 」選項 。 設定專案相關資訊 。 設定專案架構 。 設定專案圖示 。 選擇要建立的活動 (Activity) 類型 。 設定活動內容. 啟動 Eclipse. 啟動 Eclipse. 執行「 File>New>Android Application Project 」選項. 設定專案相關資訊 (1). 設定專案相關資訊 (2). 設定專案架構. 設定專案圖示. - PowerPoint PPT Presentation
Citation preview
• 啟動 Eclipse 。• 執行「 File>New>Android Application Projec
t 」選項。• 設定專案相關資訊。• 設定專案架構。• 設定專案圖示。• 選擇要建立的活動 (Activity) 類型。• 設定活動內容
+ 右擊專案檔名+ 選 Properities/Android+ 選擇適當版本
+ 從 Eclipse 執行「 Window>Android Virtual Device Manager 」。
+ 按右上角的「 New 」鈕,以建立一個新的AVD 。
+ 設定 AVD 參數。+ 將新建的 AVD 增至對話框的 AVD 清單中。
• 開啟「 Android Virtual Device Manager 」對話框。
• 選要使用的 AVD ,按「 Start 」鈕啟動 AVD 。• 按「 Lunch 」鈕關閉對話框並載入此 AVD 。• Eclipse IDE 開始模擬此 AVD 。• 模擬裝置完成載入,以滑鼠敲「 OK 」鈕啟
動此模擬裝置。• 關閉「 Android Virtual Device Manager 」對
話框。
AVD 版本需大於專案之 Android 版本,才能執行
建立 AVD 且彈出視窗後,須將後端之屬性是窗關閉,方能使用 Eclipse 之 Run/Run as configuration
+ 從 Eclipse 主畫面左面板選應用程式專案,再按工具列上的「 Run Activity_main.xml 」工具鈕。
+ 從開啟的「 Run AS 」對話框中選「 Android Application 」,然後按「 OK 」鈕。
+ 以滑鼠按模擬裝置的電源鈕,模擬將裝置關電。
• 啟動實體裝置的「 USB 除錯」功能。• 透過 USB 將實體裝置連至執行 Eclipse 的電
腦。• 從 Eclipse 主畫面左面板選應用程式專案,
再執行「 Run>Run As>1.Android Application 」選項。
• 從開啟的「 Android Device Chooser 」對話框,先選「 Choose a running Android device 」 ( 連至電腦執行中的實體裝置 ) ,然後從顯示的清單中點選你的實體裝置。
+ 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
+ 於手機上點擊 [ 設定 ]+ 點選 [ 開發人員選項 ]+ 點選 [USB 偵錯 ]+ ? 允許 USB 偵錯嗎 ?[ 確定 ]
+ src :此資料夾用以存放原始程式檔。+ gen :存放 ADT 自動產生的 java 程式檔的
資料夾,其中最重要的就是 R.java , R.java內建立一個 R 類別,此類別為 res 資料夾中的每一個資源指定了唯一的 ID ,程式透過這 ID 就可引用它對應的資源。
+ assets :此資料夾預設是空的,你可以在這裡放置一些原始檔案。
• bin :專案建置後產生的輸出資料夾,包括了應用程式建置後的安裝封包 .apk 檔,及其他編譯過 (compiled) 的資源。
• libs :用以存放私有的函式庫檔案的資料夾。• res :用以存放應用程式專案所需要資源的
資料夾。• AndroidManifest.xml :專案的組態檔。• Project.properties :此檔案包含了專案的設
定。
+ <?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>
+ 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;+ }
+ }
+ <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>
+ <?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>
+ 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