0%

Tips of Android Studio

For achieving goal, preparing is not wasting time.

To be good at doing things, one must first sharpen his tools

Android Studio设置教程

Tips of AndroidStudio

ctrl+/ 注释一行代码
ctrl+shift+/注释代码块
ctrl+b查看声明
ctrl+f查找
ctrl+r替换
ctrl+shif+f 全路径查找
ctrl+shift+r 全路径替换

ctrl+number-minus 代码折叠
ctrl+number-plus代码展开
ctrl+shift+minus折叠窗口内所有代码
ctrl+shift+plus展开窗口内所有代码

ctrl+o复写方法
ctrl+alt+o清除无效包引用
ctrl+alt+l 格式化代码

Use Ctrl+Shift+Enter to complete a current statement such as if, do-while, try-catch, return (or a method call) into a syntactically correct construct (e.g. add curly braces).

Use Refactor | Copy to create a class which is a copy of the selected class. This can be useful, for example, when you need to create a class which has much in common with some existing class and it’s not feasible to put the shared functionality in a common superclass.

Ctrl+Shift+J shortcut joins two lines into one and removes unnecessary space to match your code style.

Use Alt+Up and Alt+Down keys to quickly move between methods in the editor.

Use Ctrl+J to complete any valid Live Template abbreviation if you don’t remember it. For example, type it and press Ctrl+J to see what happens.

Ctrl+E (View | Recent Files) brings a popup list of the recently visited files. Choose the desired file and press Enter to open it.

Besides recent files, you can bring up results of the usage searches you have performed recently. To do that, use the same Ctrl+E shortcut with the Find tool window having the focus, and select the desired find usages result from the Recent Find Usages popup.

Press Alt+Q (View | Context Info) to see the declaration of the current method without the need to scroll to it.

ctrl+shift+backspace 返回上次编辑点
Ctrl+Shift+Backspace (Navigate | Last Edit Location) brings you back to the last place where you made changes in the code.
Pressing Ctrl+Shift+Backspace a few times moves you deeper into your changes history.

The CodeCompletion feature can suggest a name for a variable when you declare it. For example, start typing
private FileOutputStream
and press Ctrl+Space.
You can customize name prefixes for local variables, parameters, instance and static fields in File | Settings | Code Style.

When you need to cast an expression value to the required type the SmartType code completion will help you. For example, type

String s = (

and press Ctrl+Shift+Space to see what happens.

You can comment or uncomment lines and blocks of code using Ctrl+Slash and Ctrl+Shift+Slash.
Ctrl+Slash comments or uncomments the current line or selected block with single line comments (//…).
Ctrl+Shift+Slash encloses the selected block in a block comment (//).
To uncomment a commented block press Ctrl+Shift+Slash anywhere inside it.

To navigate to the implementation(s) of an abstract method, position the caret at its usage or its name in the declaration and press Ctrl+Alt+B.

The SmartType code completion may be used after the new keyword, to instantiate an object of the expected type. For example, type

and press Ctrl+Shift+Space:

When you want to catch exceptions thrown by some code fragment, select it in the editor, press Ctrl+Alt+T (Code | Surround With) and choose try / catch. The catch blocks for all the exceptions thrown inside the block will be generated automatically.
You can customize the bodies of the generated catch blocks on the Code tab of File | Settings | File and Code Templates.
Use other items in the list to surround with other constructs.

Using Alt+Insert (Code | Generate) in the editor, you can easily generate getter and setter methods for any fields of your class.

使用Gradle设置layout子目录

1
2
3
4
5
6
7
8
9
sourceSets {
main {
jni.srcDirs = ['src/main/jni',]
res.srcDirs = ['src/main/res',
'src/main/res/layout/activity',
'src/main/res/layout/fragment',
'src/main/res/layout/item']
}
}

Ctrl+Shift+Space

The SmartType code completion greatly helps to find methods and variables that are suitable in the current context, by analyzing the expected type of the whole expression. So doing, Android Studio pinpoints the top five most suitable results and highlights them on the blue background. For example, type

and press Ctrl+Shift+Space:

The SmartType completion also works after the return keyword, in an assignment, in an argument list of a method call and other places.

Ctrl+O

You may easily override methods of the base class by pressing Ctrl+O (Code | Override Methods).

Ctrl+I

To implement methods of the interfaces that the current class implements (or of the abstract base class), use Ctrl+I (Code | Implement methods).

Android studio 插件安装

安装插件的入口有两个地方:
1) Preferences > Plugins 选择 Browse repositories 联网安装插件
2)启动界面的configure选项 -> plugins -> 弹出plugins 菜单

添加依赖库

A、在build.Gradle文件中手工添加
B、选中工程文件,F4,选择app的Dependencies标签页面,然后+,搜索关键字并下载

Shift+F6 (Refactor | Rename)

To try it, place the caret at the symbol you want to rename, and press Shift+F6 (Refactor | Rename). Type the new name in the popup window that appears, or select one of the suggested names, and press Enter.

Enter和Tab在代码提示时的区别

看图!

When using Code Completion, you can accept the currently highlighted selection in the popup list with Tab key.
Unlike accepting with the Enter key, the selected name will overwrite the rest of the name to the right of the caret. This can be especially useful for replacing one method or variable name with another.

Bookmarks!

如其名,书签。帮助快速回到指定的位置,实际使用中简直爽得不行。

f11

将当前位置添加到书签中或者从书签中移除。

shift+f11

显示有哪些书签。

ctrl + h
显示大纲

The File Structure Popup

ctrl+f12

此快捷键可以调出当前文件的大纲,并通过模糊匹配快速跳转至指定的方法。
勾选上“show anonymous classes”后其功能相当于Eclipse中的ctrl+o

Hide All Panels

ctrl + shit +F12

关闭或者恢复其他窗口。在编写代码的时候非常方便的全屏编辑框,可以更加专心的coding…

Parameter Info

ctrl+p

在调用一些方法的时候免不了会忘记或者不知道此方法需要哪些参数。ctrl+p可以显示出此方法需要的参数。必备技能之一。

Lines Edit

ctrl+y
删除行

Find Actions

ctrl+shift+a

对于没有设置快捷键或者忘记快捷键的菜单或者动作(Action),可能通过输入其名字快速调用。神技!!!

例如想要编译,只需要输入”release”,则列表框中就会出现”assembleRelease”选项,选择就可以进行编译。

分析堆栈信息

Find Actions(ctrl+shift+a)输入 analyze stacktrace” 即可查看堆栈信息。

分析某个值的来源
Find Actions(ctrl+shift+a)输入”Analyze Data Flow to Here”,可以查看某个变量某个参数其值是如何一路赋值过来的。
对于分析代码非常有用。

欢迎关注我的其它发布渠道