Professional Documents
Culture Documents
CustomProjectsInAndroidStudio
Home
Projects
Login
Register
EditProfile
ChangeRegion
AboutUs
Mobile
CustomProjectsInAndroidStudio
MainMenu
Home
BookReviews
BookWatch
News
Projects
TheCore
Babbage'sBag
History
Swift'sSpreadsheets
TheStoneTapes
ProfessionalProgrammer
eBooks
ProgrammerPuzzles
BargainComputerBooks
CodeBin
IProgrammerWeekly
Tweet
WrittenbyIanElliot
Baidu
Thursday,16January2014
ArticleIndex
CustomProjectsInAndroidStudio
UsingaRecipe
StumbleUpon
Follow@Iprogrammerinfo
Reddit
DZone
2,257followers
Page1of2
AndroidStudioisdevelopingrapidly.Sorapidlythatthe
documentationisgettingwellleftbehind.Sohowdoyoucreate
acustomprojectoractivitytemplate?Inparticularhowtoyou
createasimpleblankprojecttypethatdoesn'tuseafragment.
search...
Search
SelectLanguage
Poweredby
Translate
NewArticles!
HowXAMLworks
CreatingObjectsWith
XAML
GettingStartedWith
RealSenseInC#
GettingToKnowWPF
JustJavaScriptLife
WithoutType
ConstructorAnd
InstanceOf
AndroidAdventures
BasicControlsAnd
Events
WhatisaDataScientist
andHowDoIBecome
One?
Codebreakingand
Colossus
SQLWorkshop
RemovingDuplicate
Rows
AndroidAdventures
BuildingTheUI
ExploringEdison
SettingUpTheBreakout
Boards
AndroidAdventures
ActivityAndUI
BuildingAJavaScript
Library
AndroidAdventures
GettingStartedWith
AndroidStudio1.0
GettingstartedwithMIT
AppInventor2
FuzzyLogicAnd
UncertaintyInAI
NewBookReviews!
FromMathematicsto
GenericProgramming
ThePracticeofCloud
InrecentversionsofAndroidStudiotherangeofprojects
availablechangedandthesimplestprojectyoucouldcreate
automaticallymakesuseofafragmenttohosttheUI.
Whiletheideaofusingafragmentevenforthesimplest
applicationmakesacertainamountofsense,therearetimes
whenworkingwiththeunderlyingwindowmakesbettersense.
InparticularourseriesintroducingAndroidStudioandAndroid
programmingingeneralmadeuseoftheearliersimplerproject
type.FromthepointofviewofteachingAndroidprogramming
therearemanyadvantagestoavoidingthecomplexityofa
fragmentuntillater.
AsaresultIProgrammerneededtocreateacustomproject
templateforasimpleAndroidprojectthatdidn'tusea
fragment.
Thisisthestoryofhowitwasachieved.
Onereallyimportantpoint:
Anychangesyoumaketoanytemplatefilesonlytake
effectafteryourestartAndroidStudio.
Thisdoesmaketestingmessyandifyouknowofabetterway
pleasecommenttoletusallknow.
Templatebasics
Atthemomentatleast,AndroidStudio'stemplatesarebased
ontheAndroidADTTemplatesystem,whichisinturnbased
onFreeMarker.Itisn'teasytofindthedocumentationforthis,
soIhavetakenthelibertyofpostingitintheResourcesand
ToolssectionofIProgrammer,seeAndroidADTTemplate
FormatDocument.
Templatesareusedtocreateentireprojectsand
subcomponentssuchasactivities.Youcanfindoutthedetails
inthedocumentationquotedabove.Thisarticleconcentrates
oncreatingaTemplateforasimpleblankActivityaspartofa
blankactivityprojecttype.
Thefirstproblemwehaveislocatingwherethetemplatefiles
arestored.Atthemoment,underWindows,thesearein:
C:\Users\username\AppData\Local\Android\android
studio\plugins\android\lib\templates
althoughthiscouldchange.Onewaytofindpossibletemplate
directoriesistosimplysearchforfilesendingin.ftl.
Thetemplatesthatweareinterestedinarelocatedinthe
activitiessubdirectory.Eachsubfolderprovidesanewproject
oractivitytype.
Currentlytherearefourprojecttypes:
http://www.iprogrammer.info/projects/215mobile/6843customprojectsinandroidstudio.html
1/3
3/20/2015
CustomProjectsInAndroidStudio
SystemAdministration
BlackHatPython
ElasticsearchThe
DefinitiveGuide
MasteringBitcoin
MSSQL,TSQL,and
SQLServerInterview
Questions
Javain24Hours(7e)
PerlbyExample(5thEd)
AndroidSecurity
Internals
JoeCelkosSQLfor
SmartiesAdvancedSQL
Programming5thEd
DevelopingBackbone.js
Applications
GoogleSearch
Complete!
DevelopingQuality
TechnicalInformation
SQLServer2014
BackupandRecovery
BecomingaBetter
Programmer
PopularArticles
ArraysinPython
AndroidAdventures
GettingStartedWith
AndroidStudio1.0
JavaScriptData
StructuresAssociative
Array
Gettingstartedwith
ExcelVBA
UsingtheWPF.NET4.0
DataGrid
Dumping.NET
Microsoft'sMadness
Weaktypingthelostart
ofthekeyboard
GettingStartedwithPC
Kinect
DatastructuresTrees
Gettingstartedwith
MicrosoftKinectSDK
PopularBook
Reviews
BeautifulArchitecture:
LeadingThinkersReveal
theHiddenBeautyin
SoftwareDesign
HelloWorld!Computer
ProgrammingforKids
andOtherBeginners
PracticalRaspberryPi
BeginningR:The
StatisticalProgramming
Language
Programming:Principles
andPracticeUsingC++
AlgorithmsinaNutshell
HowWeTestSoftware
atMicrosoft
TheRubyProgramming
Language
AndroidAppsMarketing
SimplyJavascript
Thesimplestthingtodotocreateanewtemplateistomakea
copyofBlankActivityandrenameittowhateveryoulikeinour
caseSimpleBlankActivity.
Thiswillgiveyouafewiconsandotherbitsandpiecesthat
youdon'treallyneedinyourfinishedtemplate,butitismuch
easierthanstartingfromscratch.
Template.xml
JustaddingtheSimpleBlankActivityfolderwillcauseAndroid
StudiotolistBlankActivitytwiceintheActivitytypes.Togive
yourtemplateanidentityofitown,thefirstfileyouhavetoedit
isTemplate.xml.
IfyouloadthisintoAndroidStudiooranyXMLeditoryou
shouldbeabletofigureoutwhatitisallabout.Itcontrolsthe
optionsthattheuserispresentedwithasthefinalpageofthe
NewProjectscreen.
Inourcaseallweneedtomodifyisthenamevariabletogive
thetemplateanewnameandweneedtoremoveanumberof
parametersthatarenolongerneeded.
Thatis,weneedtoremovetheparameternavType,andthe
parameterfragmentLayoutName.Everythingelsecanbeleft
asitis,buttherearesomeoptionalchangesyoumightwantto
maketotidythingsup.
Youcanfinddetailsofwhatsortsofparametersetc.youcan
definebylookingatthedocumentation.Onceyouhaveseen
anexampleitisfairlyobvious.
ThefinalTemplate.xmlis:
<?xmlversion="1.0"?>
<template
format="3"
revision="1"
name="SimpleBlankActivity"
minApi="7"
minBuildApi="14"
description="Createsanewsimple
blankactivity">
<categoryvalue="Activities"/>
<parameter
id="activityClass"
name="ActivityName"
type="string"
constraints="class|unique|nonempty"
suggest="${layoutToActivity(layoutName)}"
default="MainActivity"
help="Thenameoftheactivityclass
tocreate"/>
<parameter
id="layoutName"
name="LayoutName"
type="string"
constraints="layout|unique|nonempty"
suggest="${activityToLayout(activityClass)}"
default="activity_main"
help="Thenameofthelayouttocreatefor
theactivity"/>
<parameter
id="activityTitle"
name="Title"
type="string"
constraints="nonempty"
default="MainActivity"
suggest="${activityClass}"
help="Thenameoftheactivity.Forlauncher
activities,theapplicationtitle."/>
<parameter
id="isLauncher"
name="LauncherActivity"
type="boolean"
default="false"
help="Iftrue,thisactivitywillhavea
CATEGORY_LAUNCHERintentfilter,makingit
visibleinthelauncher"/>
<parameter
id="parentActivityClass"
http://www.iprogrammer.info/projects/215mobile/6843customprojectsinandroidstudio.html
2/3
3/20/2015
CustomProjectsInAndroidStudio
name="HierarchicalParent"
type="string"
constraints="activity|exists|empty"
default=""
help="Thehierarchicalparentactivity,
usedtoprovideadefaultimplementation
forthe'Up'button"/>
<parameter
id="packageName"
name="Packagename"
type="string"
constraints="package"
default="com.mycompany.myapp"/>
<thumb>template_blank_activity.png</thumb>
<globalsfile="globals.xml.ftl"/>
<executefile="recipe.xml.ftl"/>
</template>
Theglobals.xml.ftlfilesetsupsomevariableswhichapplytoall
ofthetemplatefiles.Ingeneralyoudon'thavetomodifythisas
anyglobalvariablesthatitdefinesyoucaneitheruseor
ignore.
Whatdoesmatterhoweveristherecipe.xml.ftlfile,whichisthe
scriptthatsetsuptheproject.
PrevNext>>
LastUpdated(Tuesday,21January2014)
RSSfeedofall
content
Copyright
2015i
programmer.info.
AllRights
Reserved.
Joomla!isFree
Software
releasedunder
theGNU/GPL
License.
PoweredbyJoomla!.ValidXHTMLand
http://www.iprogrammer.info/projects/215mobile/6843customprojectsinandroidstudio.html
3/3