How to import statement in Android Studio

我的梦境 提交于 2020-12-13 04:44:05

问题


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 paste for All

  • check Add unambigious imports on the fly

Mac

To import you can use option mac+Alt+O which ask for each thing, after you have to press option mac+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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!