Tips and Tricks of Android Studio

Being an Android Developer, we use a number of IDE for writing the code for our Application. For example, Android Studio, Eclipse, Visual Studio (in some cases), etc. But the most famous and the recommended one among these IDE’s is the Android Studio. Nowadays, everyone uses Android Studio to write codes for their Application because Android Studio gives us a lot of functionalities and features, that make our speed of writing codes fast. Also, we get an organized way to manage our project in Android Studio.

No prizes for guessing! In this blog, we will look upon some of the Tips and Tricks of Android Studio. It is rightly said that:

A sword never kills anybody; it is a tool in the killer’s hand.

No no, we are not going to kill anyone :)) I mean to say that we all know that Android Studio provides a number of features that can be used for faster Application development but do we use all those features? The answer is NO. But if you want to write codes in a faster and convenient way, then you must have to use all the features that Android Studio provides. So, let’s look upon some of the Tips and Tricks of Android Studio.

1. Setting the Theme

The theme of the IDE plays an important role in determining the time that we can spend on Android Studio to write code. So, a good and eye soothing theme must be there. To change the Theme and color of the Android Studio, go to File > Settings > Appearance & Behavior >Appearance > Theme and then choose the desired Theme. To change the color of the editor text, you can go to File > Settings > Editor and change the desired property. (Note: In MAC, instead of going to Settings, you can find the options in Preferences)

2. Changing Color of Logcat

Logcat is the best way to find any bug present in the application. On the Logcat, we can see each and every event going on with a particular Android Application. You can change the color of various options available in Logcat by going to File > Settings > Editor >Color Scheme > Android Logcat and change the default color by unchecking the “Inherit values from” option.

3. Fast Searching

Android Studio contains a number of features and it is impossible to remember the place from where a particular feature can be used or activated. So, in order to search these features in a very fast manner, you can use Ctrl + Shift + A (in Windows and Linux) or by using Cmd + Shift + A (in Mac).

4. Rename file/variable

There are many cases when you want to change the name of a file or a variable, but in order to do so you have to change the name at all places where these files or variables are used in the project. Don’t worry, Android Studio provides a better way of doing this. All you need to do is select a file and then right click on it and then click on Refractor > Rename or simply Shift + F6 and then enter the new name Refract the changes. This will change the file name throughout the project.

5. Split Screen

Split Screen is a new feature that is provided by almost every modern day’s IDE. By using Split Screen, you can use two screens at a time i.e. the same window will be split into two part, either vertically or horizontally. In order to split the window, right click on the tab of the file that you want to split and then choose Split Vertically/Horizontally.

6. Distraction Free Mode

You can use the Distraction Free Mode of Android Studio to remove the editor tabs and tool-windows buttons. By doing so, your focus will be on the coding part and nothing else. To enable the Distraction Free Mode, go to View > Enter Distraction Free Mode.

7. Code Completion

You can use the Postfix Code Completion to write the code in a faster way. All you need to do is press Ctrl + J or Cmd + J(in MAC) and Android Studio will give you a number of possible codes. For example, if you want to write the code for a Toast, then just write “T” and press Ctrl + J, you will be given a list of possible items. Select Toast and click Enter.

8. Working Offline

If you want your Android Studio to run faster, then you can use the Offline mode of Android Studio. To start Offline mode, Open the Preferences window by clicking File > Settings (on Mac, Android Studio > Preferences) and in the left pane, click Build, Execution, Deployment > Gradle. After that check the Offline work check box and click Apply or OK.

9. Line Number and Method Separator

You can put line numbers to your code and method separator also. This will make your code more readable. All you need to do is Click on File > Settings > Editor > General > Appearance > Select Line Number/Select Method Separators.

10. Multicursor Feature

You can edit to more than one lines at a particular instant of time. For doing so, go to a particular word and click ALT + J (Windows and Linux) or CTRL + G (for Mac). This will select the next appearance of that word in the file. Now you have to write only once.

11. Last Copy & Paste

You can choose from your last 5 Copy/Paste operations by clicking ctrl + shift + v (in Windows or Linux) or cmd + shift + v (in Mac).

12. Open Class: In order to open a class in Android Studio, press ctrl + n (in Windows and Linux) or cmd + o (in Mac).

13. Open File: To open file press ctrl + shift + n (in Windows and Linux) or cmd + shift + o (in Mac).

14. Find Declaration: You can find the declaration of any class and its method by clicking on that class and pressing ctrl + b (in windows and Linux) or cmd + b (in Mac).

15. Move between tabs: You can move between tabs by pressing alt + left/right arrow (in Windows and Linux) or cmd + shift + [ (left) and cmd + shift + ] (right) in Mac.

16. Last tab: You can switch between last tabs by using ctrl + tab (in windows and Linux) and cmd + tab (in Mac).

17. Format your code: You can format your code by using ctrl + alt + l (in windows and Linux) or cmd + option + l (in Mac). Formatting means rearranging the declaration of attributes. For example, “id” of a TextView should be written before the width and height property. This makes the code more readable.

18. Auto-indent line: You can apply indentation by using ctrl + alt + i (in Windows and Linux) or control + option + i (in Mac).

19. Find: You can find something in a file by using ctrl + f (in Windows and Linux) or cmd + f (in Mac).

20. Find and Replace: You can use find and replace feature by pressing ctrl + r (in Windows and Linux) or cmd + r (in Mac).

21. Hardcoded String to resources: You can move your hardcoded string to string.xml file or any other resources file by just clicking on the string and pressing alt + enter (in Windows and Linux) or option + return (in Mac) and then Extract String Resource.

22. Build and Run: To build and run your app, press shift + F10 (in Windows and Linux) or control + r (in Mac).

23. Last edited location: You can directly move on to the last edited location in a particular file by pressing ctrl + shift + backspace (in Windows and Linux) or cmd + shift + backspace (in Mac).

24. Close active editor tab: You can close the active editor tab by pressing ctrl + F4 (in Windows and Linux) or cmd + W (in Mac).

25. Using Plugins: You can use a number of plugins available in Android studio to improve the functionality of Android Studio. Some of these may be:

  • ADB Idea: It helps to execute adb commands to uninstall, kill, start, restart or clear an application.
  • Android Material Design Icon Generator: This plugin will help you to generate Material Design Icons for your project.
  • Git flow integration: This helps you to have a defined flow of version control of your project.
  • Genymotion plugin: It is used to provide a smooth flow for Genymotion virtual devices.
  • Key Promoter: It is used to make your own shortcut keys for a particular task.

Conclusion

Android Studio has a number of features and by using these features we can improve various things in our Android Project like Time Management, Code Formatting, Better Understanding of Code, etc. We looked upon some of these features. If you want to know more about your project in Android Studio then go to Help > Productivity Guide (Bonus tip :))

That’s it for this blog. Please let us know your favorite tips & tricks of Android Studio.

Keep Learning :)

Team MindOrks!