Android Studio : rename package, show line numbers,...

In this page, I am going to show four useful tips that are helpful to you while you are developing your Android app in Android Studio.


1. Rename package
You have two or three similar projects. The first one was completely done and the second one will be created quickly by modifying some parts of the first project. Each project cannot have the same name. So, you have to rename it.
To rename a package in Android Studio, in your project directory structure, you expand apps directory. Next, expand src directory. Double-click the main directory. Then double-click java. You will see the package name of your project. Right-click it and choose Refactor. You see a window dialog that allows you rename the package. Click Rename package button.

rename package

Then enter the new name of the package in the renaming box. Click Refactor button to finish the task.

rename package

By renaming the package, you need to update applicationId attribute in the build.gradle file to match the new package name.

applicationid

2. Import classes
In Eclipse to import a class from library into your project, you hover the mouse over the class name. Then you choose to import the class from the dialog that appears.  In Android studio, you need to click the class that you want to import. Then press Alt+Enter.

import class

3. Display java doc
In Android Studio, to display documentation of a class or method, you click on the name of the class or method. Then press Ctrl+q.

display java doc

Alternatively, you can enable the editor to display java doc when you move the mouse over the class or method. You select File from the menu. Then select Settings. Under IDE Settings, you select Editor. In the Editor window, you select the Show quick doc on mouse move checkbox.

display java doc


4. Show line numbers
Having line number displayed in code editor is helpful while you are coding and debugging your application. In Android Studio, from the menu, you select File. Then choose Settings. Under IDE Settings, you double-click Editor. After that, you select Appearance. Finally you select the Show line numbers checkbox and click OK.

show line numbers

Posted by: Dara | post date: 04-07-2015 | Subject: Android Apps Development

write programming tip




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.