Android Hello World示例–构建第一个Android应用

Hello friends, in this tutorial I will teach you how to build first android app with the help of android hello world example. I hope that before reading this tutorial you have already installed Android Studio and done environment setup that I have taught in last tutorial. If you have not done it yet then you can read it from below link.

朋友您好,在本教程中,我将教您如何借助android hello world示例构建第一个android应用。 我希望在阅读本教程之前,您已经安装了Android Studio并完成了我在上一教程中讲授的环境设置。 如果尚未完成,则可以从下面的链接中阅读。

Also Read: Installing Android Studio and Environment Setup

另请阅读: 安装Android Studio和环境安装程序

Android Hello World示例–构建第一个Android应用 (Android Hello World Example – Build First Android App)

创建Android项目 (Create Android Project)

1. When you will open Android Studio for first time you will see following screen. Select Start a new Android Studio project option.

1.首次打开Android Studio时,将显示以下屏幕。 选择启动新的Android Studio项目选项。

Android Hello World示例–构建第一个Android应用

2. Now in Application name field enter the name of the application. Enter website domain in Company Domain field. Remember that the package name will be the company domain in reverse order plus name of application. You can fill these fields according to your choice. Then click Next.

2.现在在“ 应用程序名称”字段中输入应用程序的名称 。 在公司域字段中输入网站域。 请记住,程序包名称将是公司域(按相反的顺序加上应用程序名称)。 您可以根据自己的选择填写这些字段。 然后单击“ 下一步”

Android Hello World示例–构建第一个Android应用

3. Now in the next window it will ask for Target Android Devices. It means the minimum android version on which you want your app to run. Always keep the minimum sdk version as lower as possible, so that your app can run on maximum number of devices.

3.现在,在下一个窗口中,它将询问目标Android设备。 这表示您要在其上运行应用的最低Android版本。 始终保持最低的sdk版本尽可能低,以便您的应用可以在最大数量的设备上运行。

Android Hello World示例–构建第一个Android应用

4. In the next window choose a blank activity. An activity is a screen or window in your android mobile that holds all the components like buttons, textbox, etc. Your app can have multiple activities, right now we are creating single activity app.

4.在下一个窗口中,选择一个空白活动。 活动是Android手机中的屏幕或窗口,其中包含按钮,文本框等所有组件。您的应用可以有多个活动,现在我们正在创建一个活动应用。

Android Hello World示例–构建第一个Android应用

5. In the next window you can leave all the fields as it is. Title is the name that will be shown on the activity when we will open in mobile. Activity Name is the name of the Java file, Layout Name is the XML file. We have two files for an activity, one is a Java file that contains all the logic and working related code and another is a XML file that contains the designing related code. Remember that by default Java file name is same as activity name. If you want, you can change these files name or you can also add other activities in your app depending upon your requirement.

5.在下一个窗口中,您可以保留所有字段。 标题是当我们在移动设备中打开时将在活动上显示的名称。 活动名称是Java文件的名称布局名称是XML文件。 我们有两个用于活动的文件,一个是包含所有逻辑和工作相关代码的Java文件,另一个是包含设计相关代码的XML文件。 请记住,默认情况下,Java文件名与活动名相同。 如果需要,可以更改这些文件名,也可以根据需要在应用程序中添加其他活动。

Android Hello World示例–构建第一个Android应用

6. Finally click on Finish button to create the project.

6.最后,单击“完成”按钮以创建项目。

创建Android虚拟设备(AVD) (Create Android Virtual Device (AVD))

AVD is a virtual device that is used to run and test android apps on computer. So before running your app you need to create a virtual device.

AVD是一种虚拟设备,用于在计算机上运行和测试android应用。 因此,在运行您的应用之前,您需要创建一个虚拟设备。

1. Before creating AVD you need to download some more tools and packages. So click on SDK Manager option located at top, it is shown in below screenshot.

1.在创建AVD之前,您需要下载更多工具和软件包。 因此,单击顶部的SDK Manager选项,它显示在下面的屏幕快照中。

Android Hello World示例–构建第一个Android应用

2. Now select all the packages of an API level, always choose latest API level that is available. This is the API level on which we will run and test our apps. Now install the packages, it will take few minutes or hours to download the packages depending upon you internet speed.

2.现在选择API级别的所有软件包,始终选择可用的最新API级别。 这是我们将在其上运行和测试应用程序的API级别。 现在安装软件包,根据您的互联网速度,下载软件包需要几分钟或几小时。

Android Hello World示例–构建第一个Android应用

3. After completing the package downloading, just click on the Android Device Monitor option located at the right side of SDK Manager option.

3.完成软件包下载后,只需单击SDK Manager选项右侧的Android Device Monitor选项。

4. In the next window click on Android Virtual Device Manger option.

4.在下一个窗口中,单击“ Android虚拟设备管理器”选项。

Android Hello World示例–构建第一个Android应用

5. Now click on Create button. This will open a window to create a new virtual device. In AVD Name field enter any name, after that select a device whatever you like (I would recommend Nexus S because it is standard size device). In the Target option choose Google APIs. In Skin type, choose QVGA. You can customize your virtual device like whether you want hardware keyword or not, you can manually allocate RAM size, etc. Leave all other fields as it is. Now finally click on OK button to create the device.

5.现在单击创建按钮。 这将打开一个窗口以创建新的虚拟设备。 在“ AVD名称”字段中输入任何名称,然后选择所需的设备(我建议使用Nexus S,因为它是标准尺寸的设备)。 在目标选项中,选择Google API。 在“ 皮肤类型”中,选择“ QVGA” 。 您可以自定义虚拟设备,例如是否需要硬件关键字,可以手动分配RAM大小等。所有其他字段保持原样。 现在,最后单击确定按钮以创建设备。

Android Hello World示例–构建第一个Android应用
Android Hello World示例–构建第一个Android应用

6. After that select the device and click on Start button to start it. For first time it may take some time to start the device.

6.之后,选择设备并单击开始按钮以启动它。 第一次可能需要一些时间才能启动设备。

Android Hello World示例–构建第一个Android应用

Note: In case you are getting any error related to intel HAXM or virtualization then check below article. There I have mentioned all possible solutions for these problems.

注意:如果您遇到任何与Intel HAXM或虚拟化相关的错误,请查看以下文章。 在那里,我提到了解决这些问题的所有可能方法。

Also Read: How to Solve Intel HAXM Error in Android Studio

另请参阅: 如何解决Android Studio中的Intel HAXM错误

运行Android项目 (Run Android Project)

1. When we create our new project, by default we get code to display hello world. So we don’t need to write any code.

1.在创建新项目时,默认情况下,我们会获得代码来显示世界。 因此,我们不需要编写任何代码。

2. For running the app just click on Run button located at the top. It will take some time to build the project.

2.要运行该应用程序,只需单击顶部的“运行”按钮。 构建项目将需要一些时间。

Android Hello World示例–构建第一个Android应用

3. Now a new window will open that will ask to choose a virtual device to run your project. Just choose the running virtual device and click on OK button.

3.现在将打开一个新窗口,要求您选择一个虚拟设备来运行您的项目。 只需选择正在运行的虚拟设备,然后单击“ 确定”按钮。

Android Hello World示例–构建第一个Android应用

4. Finally you can see the output as shown below.

4.最后,您可以看到如下所示的输出。

Android Hello World示例–构建第一个Android应用

So, this was the step by step guide to make your first android app. If you have doubts or getting any difficulty then feel free to ask it by commenting below.

因此,这是制作第一个Android应用程序的分步指南。 如果您有疑问或遇到任何困难,请随时在下面的评论中提问。

Happy Coding!! ???? ????

快乐编码! ????

翻译自: https://www.thecrazyprogrammer.com/2015/10/android-hello-world-example-build-first-android-app.html