简体   繁体   中英

Assign to new local variable shortcut (ctrl-2 L) in android studio

I've just moved from Eclipse to android studio. One of my most used shortcut is ctrl-2 L, which will automatically assign a variable with a name and import the necessary class.

new View();

and press Ctrl-2 L, which results in:

View view = new View();

Is there a way to do it in android studio?

You Can See Shortcut Key in Refactor -> Extract Menu

Mac Extract Variable Use Below Shortcut:

1- + + V for local variable

2- + + F for class/field variable

3- + + C for constant

I think you must use Control+Alt key for Windows

在此处输入图片说明

Well this is pretty old but here is what I did just now.

I wrote

new View()

no column and space and just typed

new View().var

and pressed CTRL+ [SPACE] here's what appears: 在此处输入图片说明

and as I press RETURN on the suggestion bubble...

在此处输入图片说明

Voila!!😍

Discovered this in a recent session on flutter using Intelli-J and since Android Studio is based on the same IDE so, it worked!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM