(Found this article is a very good article, quite practical, special share with everyone.) Share from: Http://m.open-open.com/m/lib/view/1458715872710.html hereby declares that a good memory is inferior to a bad pen, and the market is used for later use.
The original text reads as follows:
Write in front
This document was translated from Android Studio tips by Philippe Breault, altogether collecting 62 Android studio using tips and shortcuts. Based on the use of these tips, this article divides these 62 tips into common techniques (1–28), coding Techniques (29–49), and debugging techniques (50–62), divided into three parts.
Each of the tips are equipped with animated GIF, because the original image on Google photo, loading slower, this article all transferred to seven cattle.
Due to limited capacity, the translation process will inevitably be overlooked, such as the detection of errors or problems, please put in the comments, thank you.
Common skills
1. Bookmarks (Bookmarks)
- Description: This is a useful feature that allows you to make a mark (bookmark) Somewhere, so that you can jump back here.
- Call: Menu→navigate→bookmarks
- Shortcut keys:
- Add/Remove Bookmarks: F3 (OS X), F11 (Windows/linux);
- Add/Remove Bookmarks (tagged): Alt + F3 (OS X), Ctrl + F11 (windows/linux);
- Show all bookmarks: Cmd + F3 (OS X), Shift + F11 (windows/linux), Show all bookmarks list, and can be searched.
- Previous/Next bookmark: None, you can set shortcut keys in Settings.
- MORE: When you assign a tag to a bookmark, you can use the CTRL + tag to quickly jump to the marker, such as CTRL + 1, and jump to the bookmark labeled 1.
2. Collapse/Expand code block (Collapse Expand)
- Description: This operation provides a way for you to hide part of the code that you do not care about and display the key code in a more concise format. An interesting usage is to hide the code of the anonymous inner class so that it looks like a lambda expression.
- shortcut keys: CMD + "+"/"-" (OS X), Ctrl + Shift + "+"/"-" (Windows/linux);
- MORE: You can set the collapse rule in Settig→editor→general→code folding.
3. vs. Branch (Compare with Branch (Git))
- Description: If your project is managed using Git, you can compare the current file or folder to other branches. What's more useful is to let you know how much difference you have with the main branch.
- Call: Menu→vcs→git→compare with Branch
4. Alignment with shear plate (Compare with Clipboard)
- Description: Compare the currently selected section to the content on the Clipboard.
- Invoke: Right-click on the selected section and select "Compare with Clipboard" in the right-click menu.
5. Contextual information (context info)
- Description: The current scope definition exceeds the scrolling region, and performing this operation will display the context information in which it is displayed, usually displaying either the class name or the inner class class name or the currently located method name. The same applies to the XML file.
- Call: Menu→view→context Info
- shortcut keys: Alt + Q (windows/linux)
- MORE: Personally, the better use of this feature is to quickly view the parent class or interface that the current class inherits.
6. Search action (Find action)
- Description: Enter the name of an action, find it quickly, and this is a useful technique for parts that do not have shortcut keys.
- shortcut keys: CMD +shift + A (OS X), Ctrl + Shift + A (windows/linux);
- MORE: When an action has a shortcut key, it is displayed next to it.
7. Find the completion (find complection)
- Description: When you look in a file, use the auto-complete shortcut key to give the suggested words that appear in the current file;
- shortcut keys: CMD + f (OS X), Ctrl + f (windows/linux), enter some characters, and then use auto-completion;
8. Hide all panels (hide all Panels)
- Description: The toggle editor fills the entire program interface, hiding other panels. Performing the operation again will return to the state before it is hidden.
- Call: Menu→window→active Tool window→hide all Windows;
- shortcut keys: CMD +shift + F12 (OS X), Ctrl + Shift + F12 (windows/linux);
9. Highlight everything (hightlight all the Things)
- Description: This action will highlight all occurrences of a character in the current file. This is not just a simple match, it actually parses the current scope and highlights only the relevant parts.
- Call: Menu→edit→find→highlight Usages in File;
- navigate to the previous/next place: Menu→edit→find→find next/previous;
- shortcut keys: related shortcut keys, please view in the menu;
- More:
- If a method
return
or statement is highlighted throw
, all exit/end points of the method are highlighted;
- If a class definition
extend
or statement is highlighted implements
, the inherited or implemented method is highlighted;
- Highlight a
import
statement will also highlight the use of the place;
- Press ESC to exit the highlight mode;
10. Go back to the previous tool window
- Description: Sometimes you jump from one tool window to the editor, and then you need to go back to the one that you just manipulated, such as when you look for usage, and use this action to jump to the previous tool window without using the mouse.
- shortcut keys: F12;
11. Previous Edit Location
- Description: This action will allow you to navigate to the last place you changed, which is not the same as clicking the back arrow on the toolbar back to the previous location, and the action will return to the previous edit location.
- shortcut keys: CMD + SHIFT + Delete (OS X), Ctrl + SHIFT + Backspace (windows/linux);
12. Jump between method and inner class (Move between Methods and Inner Classes)
- Description: This action lets the cursor jump between the current file's method or the name of the inner class.
- Call: Navigate→next method/previous Method;
- shortcut keys: Ctrl + up/down (OS X), Alt + Up/down (windows/linux);
13. Locating nested files (Navigate to Nested file)
- Description: Sometimes you have a bunch of files that are stored in different directories, such as files under different modules, and
AndroidManifest.xml
when you want to locate a file, you get a bunch of search results, and you have to identify what you need. You can find the correct one at the first attempt by entering the prefix of the partial path in the search box and adding the slash number.
- shortcut keys: SHIFT + CMD + O (OS X), SHIFT + Ctrl + N (windows/linux);
14. Navigate to Parent class (Navigate to Parent)
- Description: If the cursor is in a method that inherits the parent class override, this action will navigate to where the parent class is implemented. If the cursor is on the class name, navigate to the parent class name.
- Menu→navigate→super Class/method
- shortcut keys: CMD + u (OS X), Ctrl + u (windows/linux);
15. Open the Panel according to the number (open a panel by its No.)
- Description: You may have noticed that some panels have a number to the left of their names, and there is a quick action to open them. If you don't see the name of the panel, click the Toggle button in the lower-left corner of the IDE.
- shortcut keys: CMD + number (OS X), Alt + number (windows/linux);
16. Open file on external externally
- Description: with this shortcut, simply click tab to open the location of the current file or any upper path to the file.
- shortcut keys: CMD + click Tab (OS X), Ctrl + click tab (windows/linux);
17. Parameter information (Parameter info)
- Description: This operation will display the same argument list as you would write in the method declaration, which is a useful operation when you want to see the parameters of an existing method. The parameters under the cursor are displayed in yellow, and if no parameters are shown in yellow, it means that your method call is not valid and it is possible that a parameter assignment is incorrect. (for example, a floating-point number is assigned to an integer parameter). If you are writing a method call, suddenly leave the edit place, and then return, enter a comma, you can re-trigger the parameter information.
- shortcut keys: CMD + P (OS X), Ctrl + U (windows/linux);
18. Quick View definition (Quick definition Lookup)
- Description: did you ever want to see a method or a specific implementation of a class, but don't want to leave the current interface? This action will help you get it done.
- shortcut keys: Alt + space/cmd + Y (OS X), Ctrl + Shift + I (windows/linux)
19. Recently modified documents (recently Changed files)
- Description: This action is similar to the recent access (recents) pop-up window, which displays a list of recently modified files, arranged according to the modified time. You can enter characters to filter the list results.
- shortcut keys: CMD + SHIFT + E (OS X), Ctrl + SHIFT + E (windows/linux)
20. Recent visits (recents)
- Description: This operation allows you to get a searchable list of recently accessed files.
- shortcut keys: CMD + E (OS X), Ctrl + E (windows/linux)
21. Related documents (related file)
- Description: This action helps to easily jump between layout files and activity/fragment. This is also a quick action, on the left side of the class name/Layout top.
- shortcut keys: CTRL + CMD + up (OS X), CTRL + Alt + Home (windows/linux)
22. Go back to the editor (return-to the editor)
- Description: a whole bunch of shortcut keys will take you away from the editor (type hierarchy, find usages, etc.). If you want to go back to the editor, you have two options:
- ESC: This action simply moves the cursor back to the editor.
- SHIFT + ESC: The action closes the current panel and then moves the cursor back to the editor.
- Shortcut keys:
- Return but leave the open panel: ESC
- Close the panel and return: Shift + ESC
. Select in
Description: take the current file and ask you where to select the file. With all due respect, the most useful thing is to open the file in the project structure or in the resource manager. Each operation has a number or letter prefix that can be used to quickly jump through the prefix. Normally, I will ALT + F1 then enter to open the project view and then use ALT + F1 to find the file in OS X Finder. You can use this action in the file or directly in the project view.
shortcut keys: Alt + F1;
24. Expand/Reduce Options (Extend/shrink Selection)
- Description: The operation gradually expands/shrinks the current selection within the context. For example, it selects the current variable, selects the current statement, and then selects the entire method, while narrowing the selection is the opposite.
- shortcut keys: Alt + up/Down (OS X), Ctrl+w/ctrl + Shift + W (Windows, Linux)
Sublime text-style multiple selections (Sublime text Multi Selection)
- Description: This feature is super awesome! The operation recognizes the current selected string, selects the next same string, and adds a cursor. This means that you can have multiple cursors in the same file, and you can enter anything at the same time at all cursors.
- shortcut keys: Ctrl + G (OS X), Alt + j (Windows, Linux)
26. File structure pop-up window (the filename Structure Popup)
27. Switcher (The Switcher)
Description: This shortcut is basically the IDE's Alt+tab/cmd+tab command. You can use it to toggle the Navigation tab or the Panel. Once you open this window, you can quickly select it by pressing the CTRL key as you go along with the corresponding numeric or letter shortcuts. You can also use the BACKSPACE key to close a selected tab or panel.
shortcut keys: Ctrl + Tab
28. Version control action Pop-up window (VCS Operations Popup)
- Description: This action will show you the most common version control actions. If your project is not managed with version control software like Git, it will at least give you a local history maintained by the IDE.
- shortcut keys: Ctrl + V (OS X), Alt + ' (windows/linux)
Coding Tips
29. Column selection/block selection (column Selection)
- Description: When selected normally, when you select downward, the current line to the end of the line is selected directly, and in block selection mode, it is selected according to the rectangular area selected by the mouse.
- Call: hold down ALT and drag the mouse to select it.
- Open/Close block selection: Menu→edit→column Selection Mode
- shortcut keys: Toggle block Selection Mode: CMD + SHIFT + 8 (OS X), SHIFT + Alt + Insert (windows/linux);
30. Statement completion (complete Statement)
- Description: This method will generate missing code to complement the entire statement, the common usage scenario is as follows:
- Adds a semicolon at the end of the line, even if the cursor is not at the end;
- Generate parentheses and braces for if, while, for statements;
- After the method declaration, add the brackets;
- Call: Menu→edit→compelete Current Statement
- shortcut keys: CMD + SHIFT + ENTER (OS X), Ctrl + SHIFT + ENTER (windows/linux);
- MORE: If a statement has been completed, when you perform the operation, it jumps directly to the next line, even if the cursor is not at the end of the current line.
31. Deleting lines (delete line)
- Description: If unchecked, deletes the row where the cursor is located and, if selected, deletes all rows that are selected.
- shortcut keys: CMD + Delete (OS X), Ctrl + Y (windows/linux)
32. Row copy (Duplicate line)
- Description: copies the current line and pastes it to the next line, which does not affect the contents of the Clipboard. This command is useful in conjunction with the Move Line shortcut key.
- shortcut keys: CMD + d (OS X), Ctrl + D (windows/linux)
33. Writing Regular Expressions (Edit Regex)
- Description: writing regular Expressions using Java is a difficult thing to do, mainly because:
- You have to avoid the backslash;
- To tell the truth, it is very difficult;
- Look at the second one.
What can the IDE do to help us do something? Of course is a comfortable interface to write and test the regular ~- shortcut:Alt + enter→check regexp
34. Use Enter and tab for code completion differences (enter vs tab for code completion)
- Description: When the code is complete, you can use enter or tab to do the completion, but the two are different.
- When using enter: Inserts the complete code from the cursor and does nothing with the original code.
- When using tab: Insert the complete code from the cursor and delete the following code until you encounter a dot, parenthesis, semicolon, or space.
35. Extraction methods (Extract method)
- Description: extracts a block of code to generate a new method. This technique is useful when you find that a method is too complex to extract a piece of code into a separate method.
- Call: Menu→refactor→extract→method
- shortcut keys: CMD + ALT + M (OS X), Ctrl + ALT + M (windows/linux);
- MORE: In the Extract Code dialog box, you can change the modifier of the method and the variable name of the parameter.
36. Extracting parameters (Extract Parameter)
- Description: This is a quick action for extracting parameters. This technique is useful when you think you can refine a method by extracting parameters. The operation takes the current value as an argument to a method, places the old value where the method call is, and takes the passed-in parameter.
- Call: Menu→refactor→extract→parameter
- shortcut keys: CMD + ALT + P (OS X), Ctrl + ALT + P (windows/linux);
- MORE: by ticking "delegate", you can keep the old method overloaded and generate a new method.
37. Extracting variables (Extract Variable)
- Description: This is a quick action for extracting variables. When you write a value directly without writing a variable declaration, this is a convenient operation to generate a variable declaration, and also gives a suggested variable name.
- Call: Menu→refactor→extract→variable
- shortcut keys: CMD + Alt + V (OS X), Ctrl + Alt + V (windows/linux);
- MORE: When you need to change the type of a variable declaration, such as using List instead of ArrayList, you can press SHIFT + TAB to display all available variable types.
38. Built-in (inline)
- Description: When you start to get a little excited about the extraction operation, suddenly feel something too much, how to do? This is the opposite of a and extract operation. This action is valid for methods, fields, parameters, and variables.
- Call: Menu→refactor→inline
- shortcut keys: CMD + ALT + N (OS X), Ctrl + ALT + N (windows/linux);
39. Merging lines and text (Join Lines and literals)
- Description: This operation is much more cool than pressing the DELETE key at the end of the line! This action follows the formatting rules, while:
- Merge two lines of annotations while removing superfluous
//
;
- Combine multiple lines of string, remove
+
and double quotation marks;
- Declaration and initialization assignment of a merge field;
- shortcut keys: Ctrl + Shift + J;
40. Dynamic templates (Live Templates)
- Description: A dynamic template is a quick way to insert snippets, and the interesting thing about using dynamic templates is that you can parameterize the template with the appropriate default values that will guide you through the parameters when you insert the code snippet.
- MORE: If you know the abbreviation of the template, you do not have to use the shortcut key, just type the abbreviation and use the TAB key to complete it.
- shortcut keys: CMD + j (OS X), Ctrl + j (windows/linux);
41. Move the line up or down (move Lines up)
- Description: You can move the line up or down without copying and pasting.
- shortcut keys: Alt + Shift + up/down;
42. Moving method (move Methods)
- Description: This operation is similar to moving a line operation, but the operation is applied to the entire method, and the entire method block can be moved before or after the other method without copying or pasting. The actual operation is called a "move statement", which means that you can move any type of statement, and you can easily adjust the order of fields or inner classes.
- shortcut keys: CMD + Alt + up/down (OS X), Ctrl + Shift + up/down (windows/linux);
43. Take the inverse complement (negation completion)
- Description: Sometimes you automatically fill in a Boolean value and then go back to the value to add an exclamation point to complete the reverse operation, now you
!
enter
can skip these tedious operations by using the input instead of completing the completion operation.
- shortcut keys: When the code is complete,
!
you can press (sometimes you need to select the candidate);
44. Suffix completion (Postfix completion)
- Description: You can think of the operation as a code completion that generates code before the dot, not after the dot number. In fact, you call this operation the same as normal code completion: Enter a point number after an expression.
For example, to iterate over a list, you can type myList.for
, and then press the TAB key to automatically generate the for
loop code.
Call: You can enter a point number after an expression, a candidate list, in the general code completion prompt can see a series of suffix complement keyword, similarly, you can also Editor → Postfix Completion
see a series of suffix complement keyword.
The commonly used suffix complement keywords are:
- . for (complete foreach statement)
- . Format (Use
String.format()
Package a string)
- . Cast (Use type conversion package an expression)
45. Refactoring (Refactor this)
Description: This action shows all the refactoring methods that are feasible for the currently selected item. This list can be quickly selected with a numeric sequence number.
shortcut keys: CTRL + T (OS X), CTRL + ALT + Shift + T (windows/linux)
46. Renaming (Rename)
- Description: You can rename variables, fields, methods, classes, and packages by doing this. Of course, this will ensure that the renaming is meaningful to the context and will not replace the names in all the files without a brain;
- shortcut keys: Shift + F6
- MORE: If you forget this shortcut, you can use the quick Fix shortcut key, which usually contains the rename option.
47. Semicolon/dot complement (semicolon dot completion)
- Description: Code completion this feature is awesome! We're probably all familiar with the following: Start typing something, then get some suggested options from the IDE, and then choose the completion code we want with enter or tab. In fact there is another way to select the completion of the code: we can enter a point (.) or a semicolon (;). This completes the completion and adds the selected characters. This is especially useful when you end a statement completion or a fast-chained call method.
- Note: If you want the code completion method to require parameters, these parameters will be skipped.
- shortcut keys: Autocomplete + "." or ";"
48. Package code (Surround with)
Description: This action can wrap a selected block of code with a specific code structure, usually an if statement, a loop, a try/catch statement, or a runnable statement. If you do not select anything, the operation wraps the current entire line.
shortcut keys: CMD + ALT + t (OS X), Ctrl + ALT + T (windows/linux)
49. Remove the package code (Unwrap Remove)
Description: This action removes the surrounding code, which may be an if statement, a while loop, a try/catch statement, or even a runnable statement. The operation is exactly the opposite of the package code (Surround with).
shortcut keys: CMD + SHIFT + DELETE (OS X), Ctrl + SHIFT + DELETE (windows/linux)
Debugging Tips
50. Analyzing incoming data streams (Analyze data flow to here)
- Description: This action will parse the path that is passed here, based on the currently selected variable, parameter, or field. This is a very useful operation when you enter a strange code and try to understand how a parameter is passed here.
- Call: Menu→analyze→analyze Data Flow to Here
- shortcut key: None, can be specified in Settings.
- the opposite: analyze the outgoing data flow from here, which will parse the path passed down the currently selected variable until the end of the Analyze.
51. Stack trace Analysis (Analyze Stacktrace)
- Description: This operation reads a copy of the stack trace information and makes it clickable like Logcat. When you copy a stack trace from a bug report or a terminal, it's easy to debug.
- Call: Menu→analyze→analyze Stacktrace
- shortcut key: None, can be specified in Settings.
- MORE: You can also analyze a confusing stack trace by using the Proguard unscramble Plugin plugin.
52. Associated Debug Program (Attach Debugger)
- Description: start the debugger at any time, even if you are not starting your app in debug mode. This is a handy operation because you do not have to redeploy your app in debug mode in order to debug the program. You can also quickly enter debug mode when someone else is testing the app and suddenly encounters a bug and gives you the device.
- Invoke: Click the toolbar icon or Menu→build→attach to Android Process
- shortcut: None, can be specified in the settings, or click on the toolbar corresponding to the icon.
53. Conditional breakpoint (Conditional breakpoints)
- Description: Simply put, the breakpoint is triggered when the set condition is met. You can enter a Java Boolean expression based on the current scope, and the conditional input box supports code completion.
- Call: Right-click the breakpoint where you want to fill in the expression, and then enter the Boolean expression.
54. Disabling breakpoints (Disable breakpoints)
- This action will make the breakpoint. This is handy when you have a breakpoint that has a complex condition set or a log breakpoint that is not currently needed, but is not recreated the next time.
- Call: hold down ALT, and then click the breakpoint.
55. Evaluating expressions (Evaluate expression)
- Description: This operation can be used to view the contents of a variable and to calculate almost any valid Java expression. It is important to note that if you modify the state of the variable, the state will remain after your recovery code is executed.
- shortcut key: in the breakpoint state, the cursor is placed at the variable, press ALT + F8, you can display the Calculation Expression dialog box.
56. Review variables (Inspect Variable)
- Description: This action allows you to review the value of an expression without opening the Calculation Expression dialog box.
- shortcut keys: in Debug state, hold down the ALT key, and then click the expression.
57. Log breakpoint (Logging breakpoints)
- Description: This is a very useful operation when you want to print a log instead of pausing a breakpoint, and then re-deploy the project when you wish to print some log information but do not want to add
log
code.
- Call: Right-click on the breakpoint, uncheck
Suspend
it, then tick on and Log evaluated Expression
enter the log information you want to print in the input box.
58. Tagged objects (Mark object)
- Description: When you are debugging, this action allows you to add a tag to a particular object so that you can quickly identify it later. When debugging, it's a very useful operation to see whether an object is the same as before in a bunch of similar objects.
- Call: Right click on the object you need to tag, select
Mark Object
, enter tag;
- shortcut key: when the object is selected, press F3 (OS X), F11 (Windows/linux);
59. Show the current run point (show execution points)
- Description: This action will immediately move your cursor back to the current debug location.
The usual situation is: 1. You trigger a breakpoint at some point 2. Then browse freely in the file 3. Call this shortcut directly to quickly return to the previous step of debugging the place.
- shortcut keys:(Debug) Alt + F10;
60. Terminate process (stop processes)
- Description: This operation terminates a task that is currently running. If the number of tasks is greater than one, a list is displayed for you to select. This is especially useful when terminating debugging or aborting compilation!
- shortcut keys: CMD + F2 (OS X), Ctrl + F2 (Windows, Linux);
61. Temporary breakpoint (temporary breakpoints)
Description: This action allows you to add a breakpoint that will be automatically removed the first time it is hit.
shortcut keys: ALT + left mouse button click Code left (mouse), CMD + Alt + Shift + F8 (OS X), Ctrl + Alt + Shift + F8 (windows/linux)
62. Call the Level tree pop-up window (the Hierarchy Popup)
The strongest Android Studio uses tips and shortcuts "Non-original"