When you write java code in Android Studio, you always need to import some classes which you used in 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 below steps.
- Click File —> Settings menu item.
- Click Editor —> General —> Auto Import in the popup dialog.
- In the right panel, choose All from the Insert imports on paste drop down list. Check Add unambiguous imports on the fly and all other check box. Click OK button.
- Now when you write or paste a class name in your java source code, android studio will automatically import the class with it’s package.
- If you select Ask in Insert imports on paste drop down list. Then android studio will ask you whether import the class or not, you can press Alt+Enter to import it.
1.2 For MacOS
If you use MacOS, the only difference is where you can configure above settings.
- Just click Android Studio —> Preferences. The subsequent settings are very similar.
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 by below steps.
- Click File —> Settings, in the popup dialog click Keymap in left panel.
- In right panel, you can see all the keymap shortcuts listed in different category. You can read or edit shortcut there also.