Android studio best 45 tips and tricks
Android studio best 45 tips and tricks

This post covers Android studio best 45 tips and tricks that you should know as a app developer.

To know more tips check my other page Android studio helpful tips and tricks that covers 20 helpful tips and tricks.

Best Tips and Tricks

Android studio best 45 tips and tricks

1. Code Completion

Code Completion Ctrl+Space helps you quickly complete code statements. It works as you type and gives a list of suggestions available from the current caret position:

android studio tips Code Completion

2. Basic code completion

Basic code completion Ctrl+Space is available in the search field when you search for text in the current file Ctrl+F, so there is no need to type the entire string.

Basic code completion - android studio

3. When you use basic code completion Ctrl+Space, type any characters that exist anywhere in an identifier.

Android tips and tricks

4. Easy to specify colors in CSS files

The color properties have icons of the corresponding color in the editor gutter.

Click an icon to choose the desired color using the color picker.

Easy to specify colors in CSS files - Android studio

5. To select a part of your code, drag your mouse while pressing

To select a part of your code, drag your mouse while pressing - Android studio

6. You can comment and uncomment lines and blocks of code

: comment or uncomment the current line or the selected block with single line comments ( //… )
: enclose the selected block in a block comment ( // )

To uncomment a block, position the caret anywhere inside it and press Ctrl+Shift+/.

7. Easy to invoke the Commit Changes dialog

Press Ctrl+K to invoke the Commit Changes dialog.
It shows all modifications in a project, provides files' status summary and suggests improvements before checking in.

8. Compare the following via context menu commands

  • directories
  • a class or a class member with another class or class member
  • a local file with its versions in Local History
  • a local file with its current revision in your version control repository
  • any two revisions of the same file
  • any local file with the file currently opened in the Editor
  • any two local files with each other: text or binary
  • active Editor with the clipboard contents
  • any text sources you paste into a blank diff window

You can configure the Diff tool of the Settings/Preferences dialog (Ctrl+Alt+S) under Tools | Diff & Merge.

9. You can create code constructs using statement completion

Start typing a method declaration, a method call, or a statement such as if, do-while, try-catch, or return.

Press Ctrl+Shift+Enter to complete the statement into a syntactically correct construct.

10. Quickly complete a method call

To quickly complete a method call of a static method located anywhere in your project, a library or a JDK, enter a prefix and press Ctrl+Space twice. You can press Alt+Enter to import the selected method.

android studio

11. Choose favorite shell

You can use your favorite shell from the built-in Terminal.
In the Settings/Preferences dialog (Ctrl+Alt+S), go to Tools | Terminal and specify the path to your shell executable.

12. How to fix a highlighted error or warning

Press Alt+Enter in the editor to fix a highlighted error or warning, improve or optimize a code construct.

fix a highlighted error or warning - android studio

13. Refactor

Use Refactor | Copy to create a class which is a copy of the selected class.

This is useful when you need to create a class similar to an existing one, and it's not feasible to put shared functionality in a common superclass.

14. Copy Reference action

Use the Edit | Copy Reference action to insert a reference to a field/method/class/file into the current position in the editor.

Position the caret within the myMethod method name and press Ctrl+Alt+Shift+C:

To paste the reference, press Ctrl+V:

You can also copy references in the Go to Class/Go to Symbol/Go to File dialogs. Press Ctrl+C on any element in the lookup list.

15. Protect any files in your project by copyright

Do you want to protect any files in your project by copyright? Go to the Settings/Preferences dialog Ctrl+Alt+S, select Editor | Copyright | Copyright

Profiles, create a copyright profile, and add the relevant copyright variables.

For example, use $today.year to keep the copyright year up-to-date.

16. Referring to an Ant property or target

You can start referring to an Ant property or target even if it's not defined yet. Press Alt+Enter and choose Create property from the list of intention actions to create the necessary tag without lieaving your current editing location.

17. Press Ctrl+D in the editor to duplicate the selected block, or the current line when no block is selected.

18. using Code Completion

When using Code Completion, you can select the first item by pressing Ctrl+..
IntelliJ IDEA Community will insert the selected item followed by a dot or -> depending on the current context.

19. Expand selection

To expand selection, press Ctrl+W. Each time you press Ctrl+W, the selection expands to other areas of code.

For example, the selection expands from a method name to the expression calling this method, then to the whole statement, then to the containing block, and so on.

20. Accept the current selection

You can accept the current selection in the code completion suggestions list with the period key (.), comma (,), semicolon (;), space, and some other characters.

21. You can open an external file for editing by dragging it from a file browser to the editor.

22. Dedicated editor

You can edit a language injection in your code using a dedicated editor.

For example, to edit a regular expression, start typing it, press Alt+Enter and choose Edit RegExp Fragment. The regular expression opens in a separate tab in the editor, where you can type backslashes as is.

All changes are synchronized with the original regular expression, and escape characters are presented automatically. When ready, press Escape to close the regular expression editor.

language injection in your code using a dedicated editor

23. EditorConfig

You can override IDE code style settings with settings from EditorConfig

To configure the style in EditorConfig, open settings (Ctrl+Alt+S), navigate to Editor | Code Style, and select the Enable EditorConfig support checkbox.

Click Export to export the current IDE code style settings into the .editconfig file.

override IDE code style settings with settings from EditorConfig

24. Jump to a file

You can jump to a file located in a deeply nested directory by pressing Ctrl+Shift+N and typing several characters of the enclosing directories and filename.

25. To evaluate any expression while debugging your program, select the expression in the editor and press Alt+F8

26. Ignore by indexing, inspection, and code completion

You can exclude any file from your project so that it is ignored by indexing, inspection, and code completion.

In the Project tool window, right-click the file you want to exclude and choose Mark as plain text from the context menu. If necessary, you can always revert the file to its original type by the Mark as the command.

27. Documentation page

To open your browser with the documentation page for the element at the caret, press Shift+F1 (View | External Documentation).

To use this feature, a browser must be selected on the Tools | Web Browsers page of the Settings/Preferences dialog (Ctrl+Alt+S)

28. Add project elements

Alt+Shift+F lets you add project elements (files, folders, packages, instance, and class members) into a Favorites list Alt+2, which also automatically adds your bookmarks and breakpoints:

29. You can drag an external file from Explorer or Finder and drop it onto the Favorites tool window Alt+2

30. Explore the structure of the currently opened file

To explore the structure of the currently opened file, press Ctrl+F12 or select View | Tool windows | Structure. File Structure shows all classes, functions, macros, and namespaces.

Double-click an element to jump back to the source code. To locate an element, start typing its name.

Explore the structure of the currently opened file

31. If you accept a completion suggestion by pressing the exclamation mark (!), this expression will be negated

32. Code Completion suggestion

When using Code Completion, you can accept the current selection in the suggestions list with Ctrl+Shift+Enter.

IntelliJ IDEA Community will not only insert the selected string, but also turn the current code construct into a syntactically correct one (balance parentheses, add missing braces and semicolons, and so on).

33. Documentation comment tags

If a method signature has been changed, IntelliJ IDEA Community highlights the documentation comment tags that ran out of sync and suggests a quick-fix:

34. Press Alt+1 to open the Project tool window and switch focus to it

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

36. Inheritance hierarchy for a selected class

To see the inheritance hierarchy for a selected class, press Ctrl+H (Navigate | Type Hierarchy). You can also invoke the hierarchy view directly from the editor to see the hierarchy for the currently edited class.

Inheritance hierarchy for a selected class

37. View all method

To view all methods of the implemented interfaces in a class, place the caret at the implements keyword in the class declaration and press Ctrl+Shift+F7:

38. View all exit points of a method

To view all exit points of a method, place the caret at one of them, for example, the return statement, and press Ctrl+Shift+F7:

39. View all statements for exception

You can view all statements within the method where certain exceptions can be caught. Place the caret at the throws statement and press Ctrl+Shift+F7

40. To scroll a file horizontally, turn the mouse wheel while keeping pressed.

41. To preview a referenced image in a popup instead of in a separate editor tab, press Ctrl+Shift+I.

42. Live template abbreviation

If you do not remember a live template abbreviation, press Ctrl+J to see a list of suggestions. For example, type it and press Ctrl+J to see what happens.

43. Run code analysis

Use Code | Inspect Code to run code analysis for the whole project or a custom scope and examine the results in a separate window.

44. Variable refactoring

The Extract Variable refactoring wraps the selected expression into a variable. It adds a new variable declaration and uses the expression as an initializer. To invoke this refactoring, select the expression and press Ctrl+Alt+V (Refactor | Extract | Variable):

45. You can use the Extract Variable refactoring even on incomplete statements. Press Ctrl+Alt+V and choose an expression.

Conclusion

In this post, I showed you various android studio tips and tricks that you can apply in your day to day programming. to read 20 more tips, view here. If you have any questions or just want to chat with me, feel free to leave a comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *

Verified by MonsterInsights