Getting Started-Building Your First App
2013-09-20 23:44
417 查看
Creating an Android Project
Create a project with command line tools:
execute:android list targets
execute:android create project -t <target-id> -n MyProjectName -p <path-to-workspace>/MyProjectName -a MainActivtiy -k com.example.mypackage
Running Your Application
One fo the most important elements your manifest should include is the <uses-sdk>element.This declares your app's compatibility with different Android version using the
android:minSdkVersion and
android:targetSdkVersion
You should always set the
android:targetSdkVersion
as high as possible.
To run your app from a command line:
Change directories to the root of your Android project,and make sure that you have already installed apache ant tools
execute:ant debug
execute:install bin/MyProjectName-debug.apk
Building a Simple User Interface
Use match_parent is better than fill_parent.
The weight value is a number that specifies the amount of remaining space each view should consume, relative to the amount consumed by sibling views.
In order to improve the layout efficiency when you specify the weight,you should change the width of the EidtText to be zero(0dp).Setting the width to zero improves layout performance because using "wrap_content"as the width
requires the system to calculate a width that is ultimately irrelevant because the weight value requires another width calculation to fill the remaining space.
Starting Another Activity
To respond to the button's on-click event,add the android:onClick attribute to the <Button> element.The android:onClick attribute's value is the name of a method in your activity that the system calls when the user clicks the
button.
In order for the system to match this method to the method name given to android:onClick ,the signature must be exactly as shown.Specifically,the method must:
Be public
Have a void return value
Have a View as the only parameter(this will be the View that was clicked).
In Eclipse ,press Ctrl+Shift+O to import missing classes.
In order for the next activity to query the extra data, you should define the key for your intent's extra using a public constant. So add the EXTRA_MESSAGE definition to the top of the MainActivity class:
It's generally a good practice to define keys for intent extras using your app's package name as a prefix. This ensures they are unique, in case your app interacts with other apps.
Create a project with command line tools:
execute:android list targets
execute:android create project -t <target-id> -n MyProjectName -p <path-to-workspace>/MyProjectName -a MainActivtiy -k com.example.mypackage
Running Your Application
One fo the most important elements your manifest should include is the <uses-sdk>element.This declares your app's compatibility with different Android version using the
android:minSdkVersion and
android:targetSdkVersion
You should always set the
android:targetSdkVersion
as high as possible.
To run your app from a command line:
Change directories to the root of your Android project,and make sure that you have already installed apache ant tools
execute:ant debug
execute:install bin/MyProjectName-debug.apk
Building a Simple User Interface
Use match_parent is better than fill_parent.
The weight value is a number that specifies the amount of remaining space each view should consume, relative to the amount consumed by sibling views.
In order to improve the layout efficiency when you specify the weight,you should change the width of the EidtText to be zero(0dp).Setting the width to zero improves layout performance because using "wrap_content"as the width
requires the system to calculate a width that is ultimately irrelevant because the weight value requires another width calculation to fill the remaining space.
Starting Another Activity
To respond to the button's on-click event,add the android:onClick attribute to the <Button> element.The android:onClick attribute's value is the name of a method in your activity that the system calls when the user clicks the
button.
In order for the system to match this method to the method name given to android:onClick ,the signature must be exactly as shown.Specifically,the method must:
Be public
Have a void return value
Have a View as the only parameter(this will be the View that was clicked).
In Eclipse ,press Ctrl+Shift+O to import missing classes.
In order for the next activity to query the extra data, you should define the key for your intent's extra using a public constant. So add the EXTRA_MESSAGE definition to the top of the MainActivity class:
It's generally a good practice to define keys for intent extras using your app's package name as a prefix. This ensures they are unique, in case your app interacts with other apps.
相关文章推荐
- Android doc |Getting Started|部分 部分译文 --Building Your First App
- Develop--Training(二)Getting Started--Building Your First App
- 【菜鸟翻译】1.Building Your First App
- AndroidTraining学习------Building-Your-First-App-
- Building Your First App
- Building your First App
- (一)Building Your First App建立你的第一个应用
- 1.1 Building your first app
- Android Develop Training——创建你的第一个android应用程序(Building Your First App)
- Develog--Training系列(Building Your FirstApp 第一节)
- Android官方文档翻译 二 1.Building Your First App
- Android Develop Training中文翻译02 《Building Your First App》
- Building Your First App(创建你的第一个应用程序)
- Android Develop Training中文翻译02 《Building Your First App》
- 【English】Android -> Training -> Building Your First App -> Starting Another Activity
- Building Your First App
- Building Your First App笔记
- Training ------ Building Your First App ------ Building Your First App
- Creating Your First Mac App--Getting Started
- Building Your First App学习笔记