How To Auto Import All Class In Android Studio

When you write java code in Android Studio, you always need to import some classes which you used in the android application. This article will tell you how to import all used classes automatically.

1. Auto Import Classes In Android Studio.

1.1 For Windows or Linux.

  1. If your android studio is running on Windows or Linux, you can follow the below steps.
  2. Open android studio, click the File —> Settings menu item, then it will popup the Settings diaolg window.
  3. Click Editor —> General —> Auto Import menu item on the left side of the popup Settings dialog.
  4. On the right side, choose All from the Insert imports on paste drop-down list in the Java section. And check the Add unambiguous imports on the fly and all other checkboxes. Click the OK button.
  5. Now when you write or paste a class name in your java source code, the android studio will automatically import the class with its package.
  6. If you select Ask in the Insert imports on paste drop-down list in the above Settings —> Editor —> General —> Auto Import dialog window. Then android studio will ask you whether import the class or not, you can press Alt+Enter to import it.

1.2 For macOS

  1. If you use macOS, the only difference is where you can configure the above settings.
  2. Just click the Android Studio —> Preferences menu item to open the Preferences dialog window.
  3. Then click the Editor —> Auto Import menu item on the left side of the popup Preferences dialog window. The subsequent settings are very similar to section 1.1.

2. Keymap Shortcut.

  1. There are a lot of shortcuts in android studio which are very useful when you are writing java source code. If you do not remember them, you can find all the shortcuts follow the below steps.
  2. Click File —> Settings menu item in android studio ( Windos or Linux ) or Android Studio —> Preferences ( macOS ), in the popup dialog click Keymap in the left panel.
  3. In the right panel, you can see all the keymap shortcuts listed in different categories. You can read or edit shortcuts there also.

3. Create auto-import Shortcut Key In Android Studio.

  1. Below are the steps for creating an android studio shortcut key combination to auto-import all missing imports.
  2. Click android studio File —> Settings menu item.
  3. Click the Keymap menu item on the popup Settings window.
  4. Input the search keyword auto-import on the right side search box and click the enter key to search.
  5. It will list the Other —> Auto-import item below the search box, double click the Auto-import item.
  6. It will popup a menu list, select the Add Keyboard Shortcut item in the list.
  7. Then it will popup the Enter Keyboard Shortcut dialog window, input the Shortcut key combination ( such as Ctrl + Shift + O) in the First Stroke text box.
  8. Click the OK button to save the changes.
  9. Now when you press Ctrl + Shift + O at the same time, it will import all the missing import classes automatically in android studio.

4. Question & Answer.

4.1 How To Use Shortcuts To Auto Import Java Classes In Android Studio.

  1. I am a fresh man to Android Studio, I am familar with Eclipse. In Eclipse, I can use the shortcuts Shift + Ctrl + O to import all the java packages in one time. But in Android Studio, I only find the shortcuts Ctrl + Alt + O, but this shortcut will ask me to press Alt + Enter for each java package import code to accept it. Is there a way to import all java packages at one time?
  2. The shortcuts that you used Ctrl + Alt + O is not wrong. What you need to do is to configure your Android Studio like this article tell you In section 1.1 & 1.2. If you use Android Studio On Windows or Linux, please refer to section 1.1, if you use Android Studio on macOS, please refer to section 1.2.

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Clicky