So I mentioned at the end of the last
video that we were going to create
another project, so I'm going to close
this project by going up to the file
menu and selecting close project and
what we're going to do is create another
project this time based on that other
template the basic activity template.
So I'm going to a click on start new
Android studio project, so once again I'm
going to accept all the default values
for everything and uncheck the include
Cochrane support box but if you're using
Kotlin, this time keep it ticked so we're
going to click on that checkbox now, so
that you can see the difference so click
on next then we're going to go to next
again and then with this time we're
going to choose the basic activity once
we've done that we're going to click
next. So once we get here we get to name
the activity in layout but now this is a
couple of extra options compared to the
last video and we use the empty activity
the title will be shown on the toolbar
and this template adds to the project
but note that the activity name and
layout name are the same as for the
empty activity template, so we're going
to click on finish at this point and
once again Android studio should create
a basic project based on the template we
selected. Now by the way while it's
building the project it's not uncommon
to see errors on the screen but they
should clear when everything is finished
just keep an eye down here in the bottom
right hand corner and the status bar and
don't try to do anything with a project
until it's finished
it'll say something like Gradle build
finished in or words to that effect once
it's finished and how long it took when
it's done you can see don't hit the
moment it says Gradle build running you
can see down the bottom left hand corner
of Gradle build finished and we're good
to go now by the way you may also see a
message at the top of the screen about
Gradle files haven't changed this
happens from time to time with some
Android studio versions so if you do see
that click the sync now button link at
the right hand side as you can see on
the screen there when Android studio is
finished creating the project you should
see main activity and a layout called
content underscore main dot xml we can
see them both on the screen up here now
the layout looks very similar to our
empty activity layout from the last
video but there's also a floating action
button down here so we can see at the
bottom right. Now if you feeling chased
hit because the image promised you a
menu don't worry it's there but it
doesn't appear on this layout
now one difference between this template
and the empty activity one is that
Google splits the layouts for each
activity up into two different files,
content underscore main dot xml here is
the one that would be using to put our
own widgets into things like buttons and
text boxes and anything else that we
want displayed on the screen and the
floating action button live in another
file called activity underscore main dot
xml, you notice over here we've got that
file so we double click that to open it
so you can see that the toolbar the
floating action button can be selected
when I click on them so I can click on
something and notice that while I'm
doing that it's selected but if I go
back to content underscore main dot XML
I can't click the floating action button
and that's because they don't exist in
this fall although Android studio does
display the floating action button in
the preview now as I click on the
toolbar and the floating action button
back in activity underscore main those
heather's selected over the far left of
the screen over here in the component
tree and when I click on the main part
of the screen here it selects the
include line which is including the
layout called content underscore main
and you can see that over here to the
right-hand side and this is called the
attributes pane, so the idea is that the
layered is split up to keep your widgets
in a separate file from the toolbar and
the floating action button, if you wanted
to you could delete the include line and
place all your widgets in here but it's
less confusing to keep them separate now
Google introduces separations back in
Android studio 1.5 and that caused
students at the time of some confusion
well they suddenly found two layout
files in their projects now it's
possible that content underscore main
may disappear from the template in a
future version but now that you know
that content underscore main is just
included in activity in the school main
and that you don't have to keep you
widget separate if you don't want to you
shouldn't have any problems if things do
change and incidentally in this version
of Android studio the toolbars blank
even when previewing in it even when
previewing activity underscore main
and that does sometimes happen but if I
run the app the toolbar would appear,
so if you get a blank toolbar in preview
mode don't worry about it it will show
up when the app is running. Alright now
before I finish talking about templates
let's have a quick look at the main
activity file there's quite a bit more
code in this version
than in the empty activity year template
from the previous video but it's all to
do with the setting up on the floating
action button and the toolbar. Now there
are two methods or functions if you're
looking at this in the cotton course
that weren't present before on create
options menu in that on options item
selected now they used to set up the
menu and detect which menu items tapped
also there's code in oncreate to cause
the toolbar to be drawn and to allow
clicks on the floating action button to
be detected now if I don't want all that
I can just delete it. Now in the oncreate
method I'm going to go into there I'm
going to actually delete all but the
first two lines so everything from here
down to the end of the right curly brace
there I'm going to delete look so and
I'm going to delete entirely on create
options menu function and also the own
options items selected so once I do that
we basically end up with the same code
as the previous template would have
given us and by the way you can also
delete activity underscore main I can
come over here right-click and select
delete I can go ahead and ignore those
warnings click on delete anyway and
that's removed activity and let's call
main from this project and then what I
could do is rename content underscore
main to activity in this core main I
come over here and right click that
click on refactor and select rename I
change that to activity now let's call
my XML and click on refactor, now
sometimes you might get an error doing
that on a Mac or a Windows machine if
that happens just right-click and choose copy,
so if the rename didn't go through just
right-click and select copy but the
content owners called main.xml file and
select copy and paste and then choose
activity underscore - the file name and
then you'll be able to delete content
notice called main but in this case you
can see they leave renamed worked ok, so
now that I've done that notice over here
there's this exclamation mark and if you
click on that to show it we've got an
arrow down here I can scroll it up to
have a look at it it's just basically a
warning about the
that the surrounding layout did not
actually include this layout, basically
it's saying it's no longer shown inside
another layout but we don't need to
worry about that at this stage and what
we can do instead is come over here to
the text tab and by clicking on that we
can see the xml for the layout. Now you
don't need to worry about this xml very
often well though it's very helpful if
you select it and paste it all into your
question if you have a problem with a
layout not working what we can do to
remove the error is delete the tools
show in line, this line up here which is
what Android studio is essentially is
suggesting that we actually do so I'm
gonna go ahead and do that delete it
making sure that I'll leave the last
greater than sign there and put that
back in like so if we go back and click
on the design tab now notice if the
error is not valid anymore well we haven't
got a red exclamation mark anymore so we
created a project using the basic
activity template but then we changed it
to be exactly the same as the one
created with the empty activity template
now I don't expect you to remember all
of that nor be able to do it yourself
just yet but by the time you finish the
course all of what we've done will make sense.
So that's templates, they're just
templates generating common code to save
you having to type it but there's
nothing magical about them you're
completely free to make any change you
want to once Android studio is created
the project from the template.
Now if Android studio changes in the
future and temperance were these exact
names are no longer available,
you just want to choose ones that look
similar and you can always delete any
code that doesn't appear in the videos
or add any code that I have in the video
but which is missing from the template.
Alright so let's move on to the next
video where we're going to start coding
up our first app. See you in the next video.