如果先前不熟悉 IntelliJ IDEA 界面,你可能会有些懵,这篇文章就提供些入门技巧。
Figure 1. Gradle 项目文件结构图
项目文件结构
图1显示了项目文件结构,几乎所有自己项目的文件都在 src/ 文件夹中,包括资源文件 和 manifest 文件。之所以这样,是因为Android Studio采用了基于Gradle的编译系统。也就是,未来所有开发文件的修改都在 src/ 文件夹下了。参考:Gradle Plugin User Guide.
基本操作
创建虚拟设备
通过工具条上的 Android Virtual Device Manager
打开管理器,创建新的虚拟设备在模拟器中运行app。
安装SDK更新
点击工具条上的 SDK Manager
打开管理器检查更新(新工具、平台、库等)。
创建新文件
CTRL + N就可以了,如果希望直接在某个文件夹中创建,那就选中那个文件夹,然后CTRL + N。然后 Android Studio 会提供文件类型供选择。
For example, if you select a layout directory, press CTRL + N, and select Layout resource file, a dialog opens so you can name the file (you can exclude the .xml suffix) and choose a root view element. The editor then switches to the layout design editor so you can begin designing your layout.
创建布局
Android Studio 提供了布局编辑器,可以拖拽widgets 进布局,并预览,也可以同时编辑 xml。
While editing in the Text view, you can preview the layout on devices by opening the Preview pane available on the right side of the window. Within the Preview pane, you can modify the preview by changing various options at the top of the pane, including the preview device, layout theme, platform version and more. To preview the layout on multiple devices simultaneously, select Preview All Screen Sizes from the device drop-down.
You can switch to the graphical editor by clicking Design at the bottom of the window. While editing in the Design view, you can show and hide the widgets available to drag-and-drop by clicking Palette on the left side of the window. ClickingDesigner on the right side of the window reveals a panel with a layout hierarchy and a list of properties for each view in the layout.
如何调试
编译和运行app时,通过 DDMS 面板 的 adb 和设备日志了解运行信息。使用 Android Debug Monitor, 点击工具条上的Monitor
启动。
快捷键
Table 1.Programming key commands
Action
Android Studio Key Command
补全
CTRL + SHIFT + A
Project quick fix
ALT + ENTER
格式化代码
CTRL + ALT + L (Win)
OPTION + CMD + L (Mac)
显示选中 API 的文档
CTRL + Q (Win)
F1 (Mac)
显示方法参数表
CTRL + P
创建方法
ALT + Insert (Win)
CMD + N (Mac)
Jump to source
F4 (Win)
CMD + down-arrow (Mac)
删除行
CTRL + Y (Win)
CMD + Backspace (Mac)
Search by symbol name
CTRL + ALT + SHIFT + N (Win)
OPTION + CMD + O (Mac)
Table 2. Project and editor key commands
Action
Android Studio Key Command
Build
CTRL + F9 (Win)
CMD + F9 (Mac)
Build and run
SHIFT + F10 (Win)
CTRL + R (Mac)
Toggle project visibility
ALT + 1 (Win)
CMD + 1 (Mac)
Navigate open tabs
ALT + left-arrow; ALT + right-arrow (Win)
CTRL + left-arrow; CTRL + right-arrow (Mac)
For a complete keymap reference guide, see the IntelliJ IDEA documentation.