Live Templates are a compose-related tool added to Android Studio that allows you to enter code snippets for fast insertion by typing an abbreviation corresponding to a template abbreviation. Live Templates can help you optimize everyday tasks and speed up your work.

For example, when working with Compose, you can type:

  • comp to set up a @Composable function
  • prev to create a @Preview composable function
  • paddp to add a padding Modifier in dp
  • weight to add a weight Modifier
  • WWRWC to surround the current composable with a BoxRow, or Columncontainer


Built-in Live Templates

You can find the Live Templates settings in Android Studio – File > Settings > Editor > Live Templates.

Here you can see the abbreviations, descriptions, and template text for each of the Live Templates. For example, this is the Live Template for creating a composable function:


Custom Live Templates

Furthermore, besides the built-in Live Templates, you can create your own custom templates. By pressing the add icon on the right side, you can select to add a new Live Template or Template group:

When creating a Live Template, you can select the abbreviation, description, and template text to be something that can benefit your daily work.

If you haven’t used Live Templates yet, now is your chance to check them out and find or create the ones that will help you in your daily work.

Happy coding!


Spread the love

Leave a Reply

Your email address will not be published.