72

I've just switch to Android Studio 0.5.1, and the things going so slow here, because nothing works in the regular way...

How do I import the necessary classes with shortcut?

I mean like this ones?

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
Zoe
  • 27,060
  • 21
  • 118
  • 148
Ilya Libin
  • 1,576
  • 2
  • 17
  • 39

8 Answers8

132

Go to File -> Settings -> Editor -> Auto Import -> Java and make the below things:

Select Insert imports on paste value to All

Do tick mark on Add unambigious imports on the fly option and "Optimize imports on the fly*

Screenshot

Ajay S
  • 48,003
  • 27
  • 91
  • 111
  • 14
    "Android Studio" -> Preferences -> Settings for OSX – latj Jun 10 '14 at 18:04
  • 8
    Option in Mac Android Studio 1.2: Android Studio Menu --> Preferences --> Editor --> General --> Auto Import – Viker Jun 16 '15 at 08:23
  • 1
    This is current: Mac Android Studio 1.2: Android Studio Menu --> Preferences --> Editor --> General --> Auto Import – user23 Jun 16 at 8:23 – rashadb Jul 04 '15 at 00:00
  • Shortcut for Shortcut is... Just Press **CTRL+ALT+S** and Search String `Auto Import`, **Checked** and **OK** – Pratik Butani Sep 25 '15 at 07:03
  • 1
    For Latest Version of android Studio Go to File -> Settings-> Editor -> General -> Auto Import . – Hradesh Kumar Sep 14 '16 at 06:54
35

Go on the missing declaration with cursor and press alt+enter enter image description here

Pipo
  • 4,653
  • 38
  • 47
  • Thank you for the detailed competence! – rashadb Jul 04 '15 at 00:04
  • Thanks for this. Everyone else suggests the setting to enable auto import but that only works when there is no conflict, when there is you need this. – Chase Feb 04 '20 at 05:02
17

Ctrl + Alt + O to optimize imports

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
tning
  • 1,231
  • 10
  • 22
9

On my Mac Auto import option was not showing it was initially hidden

Android studio ->Preferences->editor->General->Auto Import

and then typed in searched field auto then auto import option appeared. And now auto import option is now always shown as default in Editor->General. hopefully this option will also help others. See attached screenshot screenshot

ShujatAli
  • 1,376
  • 2
  • 14
  • 26
9

To import classes on the fly :

On OSX press Alt(Option) + Enter.

Heinrich Cloete
  • 702
  • 5
  • 12
jkhosla
  • 1,677
  • 1
  • 14
  • 12
4

File -> Settings -> Keymap Change keymaps settings to your previous IDE to which you are familiar with

enter image description here

Deniz
  • 12,332
  • 10
  • 44
  • 62
3

You can also use Eclipse's keyboard shortcuts: just go on preferences > keymap and choose Eclipse from the drop-down menu. And all your Eclipse shortcuts will be used in here.

Leebeedev
  • 2,126
  • 22
  • 31
3

On Windows with Android Studio 1.5.1 : File --> Settings --> Editor --> General --> Auto Import

enter image description here

Dodi
  • 2,201
  • 4
  • 30
  • 39