Hello world 应该是大家学习每个语言的第一个程序,本文主要介绍如何通过Android Studio 纯手动创建第一个安卓项目程序,运行hello world
工具版本

新建项目

创建

设置基本信息

应用名称
包名称
保存位置
开发语言(java、Kotlin)
支持的最小版本
项目创建完成

切换视图
Android Studio有多种视图,默认的是App 可以切换到Project

尽管仍旧会自动生成一些IDEA和Gradle的文件,但是业务代码这块是没有生成的。

创建Activity
包名上右键,进行Activity的创建,创建的是Empty Activity
本文作者:程序员潇然 疯狂的字节X https://crazybytex.com/




创建资源
创建文件夹


创建文件

可以不使用默认的,使用最常用的一个LinearLayout

创建完成

关于视图
如上图所示,默认打开的是Design,也就是设计视图,其实就是可视化的拖、拽、点等操作,如果曾经接触过Dreamweaver那种工具,或者Visual Studio MFC开发,应该很清楚这种工具设计的意图。
因为Android其中非常大的一部分工作,就是UI的开发。

手工添加按钮
切换到Code视图,添加一个button

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 1"
/>

最终结果如上。
查看效果
切换到Design视图

Activity 加载布局
新增一行代码
setContentView(R.layout.first_layout)
结果如下图所示

本文作者:程序员潇然 疯狂的字节X https://crazybytex.com/
AndroidManifest 文件中注册
Activity 标签中,中需要新增:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

会发现有一处报错,修改为true即可

最终结果

模拟器
如果没有模拟器,新建模拟器,下面几种方式都可以打开设备管理器

还有

创建
左边是模拟器,右边Physical是指物理设备

选择屏幕

选择版本

其他信息设置

运行
创建好之后,就可以选择在这个设备上运行了~

一些运行、调试按钮 与IDEA中的基本差不多,不再赘述。

以上就是一个完整的手动创建的基本步骤,当然还有很多的事件添加处理等等,其他很多控件等等
后续会逐步记录,本文重点在于记录下一整个开始的过程,以便后续回顾,也并没有解释很多地方为什么那么做。
转载务必注明出处:程序员潇然,疯狂的字节X,https://crazybytex.com/thread-94-1-1.html
|