Android Studio: Using and Creating Them

48 Likes comments off

You probably already know about Android Studio’s live templates, abbreviations displayed as code completion options that insert a templated snippet into your code. There are dozens of live templates available in Android Studio. But did you know you can create your own dynamic live templates? If your least favorite piece of boilerplate code hasn’t yet been templatized, it’s easy to create your own live template. Here, we’re saving a shared preference. It’s a common pattern where typically only the key name and value vary. It’s also not uncommon to forget to call apply. Let’s copy this code and go to the Preferences menu.

Tham khao studio trang diem dep tai day :

Navigate to Editor, then Live Templates. Then select Android, and choose to Add a New Live Template. Enter an abbreviation that will be used as a shortcut and a helpful description. Then we paste in our code, fully qualify the classpaths, and replace the paths with our code snippet that will be different each time with variables. We’ll be able to tab through these when entering values. This template is applicable within the context of a Java statement. When we type a resource string name, we want it to offer us order completion options. With our live template defined, we can start typing the abbreviations. Select it from the auto completion hint by pressing Tab, and then paste it in our snippet. Enter each value, tabbing between them, and you’re done. More code with fewer keystrokes thanks to Android Studio live templates. [MUSIC PLAYING]

  How to Asana: Using Asana for Android

You might like

About the Author: admin

You cannot copy content of this page