I have a project with a lot of classes in which I need to change the Created by
template.
/**
* Created by johnnyfivedev on 19.07.16.
*/
Since there are a lot of such classes, copy and paste not an option. Rather I want to remove that generated template and regenerate it. Is there any default shortcut for doing this? If not, then how do I create one?
For creating new templates, right click on the source code folder and select “New”, then select “Edit File Templates”. Here you can see some predefined templates but we don't need this so click on “+” icon in top left corner. After this action your screen should look like this.
What is a Live Template? As mentioned towards the beginning of this tutorial, a live template is a tool in Android Studio and IntelliJ that allows you to insert frequently used bits of code into your file. You may have even run into some by accident before. You'll soon learn how customizable these can be!
Android Studio provides code templates that follow the Android design and development best practices to get you on the right track to creating beautiful, functional apps. You can use templates to create new app modules, individual activities, or other specific Android project components.
Rather I want to remove that generated template and regenerate it.
You can surely edit the template but you can't regenerate it again. I suggest editing the template for your future uses and creating a live template for those made prior to this template change.
Go to Settings -> Editor -> File and Code Templates -> Includes -> File Header
and override the ${USER}
function like so:
#set( $USER = "Your name")
If you want, you can add a lot more variables to it.
NOTE: These changes will only take effect on new files. The ones made prior to this template change will have to be manually changed.
Press Ctrl+Alt+S to go directly to the File and Code Templates tab.
Go to Settings -> Editor -> Live Templates
Press the green 'plus' sign to add a new template, and select Live Template
.
In the abbreviation
field, type what you want to, I typed annot
, add a suitable description (optional) and insert the following code in the box:
/**
* Created by $USER$ on $DATE$.
*/
$END$
Select the Edit variables
box and write the following expressions in the corresponding fields,
user()
for USERdate("dd-MM-yyyy")
for DATEAfter that type define applicable contexts as you see fit. In your code, now type annot
and press Enter to insert the template.
In the code, your cursor will end up at the place of $END$
upon pressing Enter after template insertion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With