问题
import android.text.EditText;
I can't import anything, when I press ALT + Enter it appeared create test instead of import class, variable and all that. How to import the syntax above?
回答1:
Windows/Linux
To import you can use Ctrl+Alt+O which ask for each thing, after you have to press Alt+Enter to accept it.
If you want to change this behaviour to organize all imports go to File -> Settings -> Editor -> General -> Auto Import -> Java and:
change
Insert imports on pasteforAllcheck
Add unambigious imports on the fly
Mac
To import you can use
+Alt+O which ask for each thing, after you have to press
+Enter to accept it.
To change all behaviour are same steps but location is in Android studio > Properties...
回答2:
Android Studio provide great facility to create application in Android. But when I try to paste some code copied from Internet in Editor, it ask me to import every Views and classes. You can simply import all of them by pressing ALT + ENTER key. It is very tedious work to import each and every component by pressing ALT + ENTER.
But, what if I want to import library and all other classes at once. I found a solution for that.
Go to File -> Settings -> Editor -> Auto Import -> Java
make the following changes:
change Insert imports on paste value to All from Drop Down menu Add unambigious imports on the fly option as checked Now, click on APPLY and OK to save changes.
This will auto import all the classes when you PASTE any code in editor.
回答3:
Use Ctrl+Shift+O to organize imports.
来源:https://stackoverflow.com/questions/30731160/how-to-import-statement-in-android-studio