樹心幽徑

« 20200109自selldb資料庫的custs資料表選擇要刪除的資料錄來刪除的PHP程式(c3.php) | Main | 20200124安裝魯地圖、MapSource、BaseCamp、GoogleEarth並用LIBRE-OFFICE 的CALC試算表及notepad記事本來製作伊加之蕃的kml及gpx航跡檔 »

20200112設計第一個Android APP:自訂程式標題、文字物件與按鈕
2020/01/12,11:49

REF1  : https://readandplay.pixnet.net/blog/post/140001110

ref2 : 把APP安裝到手機裡

ref3:新增一個按鈕、加上點擊的事件

ref4:<Android> Button OnClickListener 事件三種做法

ref5:【APP/Android】onClick事件的5種實現方式

 

(1)下載Android Studio  App 開發工具(android-studio-ide-191.6010548-windows.exe)

https://developer.android.com/studio 3.5.3 for Windows 64-bit (718 MB)

(2)安裝完成並啟動IDE/下載各式組件(約573MB)「...COMPONENTS:SDK Tools、Patch Applier、emulator(262MB)、platform(75MB) 、build-tools(38MB)、Intel x86 Emulator Accelerator (HAXM installer)、sources(38MB)...」

:

Downloading https://dl.google.com/android/repository/sdk-tools-windows-4333796.zip
Downloading https://dl.google.com/android/repository/3534162-studio.sdk-patcher.zip
Downloading https://dl.google.com/android/repository/emulator-windows-6110076.zip
Downloading https://dl.google.com/android/repository/platform-tools_r29.0.5-windows.zip
Downloading https://dl.google.com/android/repository/extras/intel/haxm-windows_v7_5_4.zip
Downloading https://dl.google.com/android/repository/platform-29_r04.zip
Downloading https://dl.google.com/android/repository/build-tools_r29.0.2-windows.zip
Downloading https://dl.google.com/android/repository/sources-29_r01.zip
Running Intel® HAXM installer
:

(3-1)「Start a new Android Studio project」:建立新專案/「Creates A New Empty Activity」

(3-2)輸入並設定如下內容:「name: TreeHeartFirst」/「Package name:com.example.treeheartfirst」/「Save Location:C:\Users\treehrt\AndroidStudioProjects\TreeHeartFirst」/「Langauage:java」/「Minimum API level : API 15」

(3-3)syncing :下載gradles distribution

(3-4)下載Kotlin plugins

(3-5)允許存取「OpenJDK Platform binary」

 

(4-1) 點選app/res/layout/下的「activity_main.xml」或「content_main.xml」並修改TextView物件預設的顯示文字.

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="H黑熊問候大家好!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

(4-2) 點選「app/res/values/strings.xml」並修改app_name如下:

<string name="app_name">Treehrt5:TaiwanBlackBear台灣黑熊</string>
<string name="buttonText">BlackBear!黑熊來了</string>
<string name="buttonOnClickMessage">按了</string> 

(4-3) 點選app/res/layout/下的「content_main.xml」的TextView下加入如下文字:

<Button
 
    android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/buttonText"
   android:onClick="buttonOnClick
/>
(4-4)開啟app/java/[專案id]/MainActivity.java

void buttonOnClick(View view) {
Toast toast = Toast.makeText(this, R.string.buttonOnClickMessage, Toast.LENGTH_SHORT);
toast.show();
}

(5-1)新增ANDROID模擬器:「Open AVD Manger」/CreateVitualDevice/選「Phone: Pixel 3a」/選「Android 10.0」

(5-2)下載並安裝Google Play Intel x86 Atom System Image第8版 (system-images;android-29;google_apis_playstore;x86)API LEVEL: 29  約1.1GB

(5-3) AVD NAME: Pixel 3a API 29

(5-4)按下「Pixel 3a模擬器」旁的執行鈕即可出現執行結果。

alt

 

(6) 如果執行的APP一直卡在「Waiting for Target Device to Come Online」,進行如下操作即可解決:

AVD Manager---Right Click Emulator----Wipe Data----Run App Again


迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType