Title : Live Templates in Android Studio: Using and Creating Them
link : Live Templates in Android Studio: Using and Creating Them
Live Templates in Android Studio: Using and Creating Them
You probably already knowabout Android Studio's live templates,abbreviations displayed as code completion optionsthat insert a templated snippet into your code.
There are dozensof live templates available in Android Studio.
But did you know you cancreate your own dynamic live templates? If your least favoritepiece of boilerplate code hasn't yet beentemplatized, it's easy to create yourown live template.
Here, we're savinga shared preference.
It's a common pattern wheretypically only the key name and value vary.
It's also not uncommonto forget to call apply.
Let's copy this code andgo to the Preferences menu.
Navigate to Editor,then Live Templates.
Then select Android, and chooseto Add a New Live Template.
Enter an abbreviationthat will be used as a shortcut anda helpful description.
Then we paste in our code,fully qualify the classpaths, and replace the pathswith our code snippet that will be differenteach time with variables.
We'll be able to tab throughthese when entering values.
This template is applicablewithin the context of a Java statement.
When we type aresource string name, we want it to offer usorder completion options.
With our livetemplate defined, we can start typingthe abbreviations.
Select it from theauto completion hint by pressing Tab, and thenpaste it in our snippet.
Enter each value, tabbingbetween them, and you're done.
More code with fewer keystrokesthanks to Android Studio live templates.
[MUSIC PLAYING].
Thus Article Live Templates in Android Studio: Using and Creating Them
You now read the article Live Templates in Android Studio: Using and Creating Them the link address https://svedda79.blogspot.com/2016/02/live-templates-in-android-studio-using.html
0 Response to "Live Templates in Android Studio: Using and Creating Them"
Post a Comment