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.

If your android studio is running on Windows or Linux, you can follow the below steps.

  1. Click File —> Settings menu item.
    android-studio-file-settings
  2. Click Editor —> General —> Auto Import menu item on the left side of the popup Settings dialog.
    android-studio-file-settings-editor-general-auto-import
  3. On the right panel, choose All from the Insert imports on paste drop-down list. Check Add unambiguous imports on the fly and all other checkboxes. Click the OK button.
    android-studio-aotu-import-settings
  4. 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.
  5. If you select Ask in 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.
    android-studio-ask-to-import-classes

1.2 For macOS

If you use macOS, the only difference is where you can configure the above settings.

  1. Just click Android Studio —> Preferences. Then click the Editor —> Auto Import menu item on the left side of the popup Preferences dialog window. The subsequent settings are very similar.
    android-studio-macos-configure-auto-import-classes

2. Keymap Shortcut.

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.

  1. Click File —> Settings, in the popup dialog click Keymap in the left panel.
    android-studio-keymap-shortcut-settings
  2. 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 a 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 serch.
  5. It will list the Other —> Auto-import item below the serch 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.
0 0 vote
Article Rating
Subscribe
Notify of
guest

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

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x