Search code examples
android-studiointellij-ideaautocompletekeyboard-shortcutscode-completion

Android Studio code auto-completion


It's my first question on stackoverflow, I've searched for an answer to my question but couldn't really find an exact answer to the one I have so please don't slap me too much if this will sound trivial.

Earlier on I was typing in Toast.makeText while writing my Android application and I've pressed something on the keyboard (it couldn't have been much more than Enter + something) that not only auto completed the code in the way Toast.makeText(); but also added all 3 parameters for me, including name of the activity I was currently in as the context (OrderHistoryScreenActivity.this).

I found something similar regarding IntelliJ (https://www.jetbrains.com/help/idea/2016.3/smart-type-code-completion-completing-code-based-on-type-information.html#d1916089e66) but it's not exactly what happened to me since according to this article I need to press Ctrl + Shift + Space multiple times to have the selection dialog pop up for each parameter, rather than having all auto completed in one go as it has previously happened.

Thank you for help!


Solution

  • I came across your question by experiencing exactly the same thing!

    I found this feature is called Live Templates and you can activate it by hitting Tab after typing in the word Toast. here is a screenshot showing the intention icon for the 'Toast' keyword.

    screenshot of Toast live template

    if you type in Toast and then a full-stop, the feature does not activate.

    Android Studio Live Templates documentation