Hello this is Martez awkwardly and in this eternally old your way to learn about custom views in Android.
So let's create a new Android studio project and the for the application name to step in here custom
view app and you can specify the company domain project location.
And here we can specify the Peggys package name if you want to change this package name we just need
to click on it here.
We don't want to add C++ or cosmoline to our project so don't check these checkboxes here and just click
next and here as the minimum API I chose our Android five point one if you want to you can change it
to for example Android 4.1 jelly bean.
OK.
And just click on next.
So here choose empty activity next.
And here don't change anything and just click on finish.
OK so now that a project is created we need to open the Android view here at the left hand side and
then open this app folder.
Here we have this reservoir there open it.
So now we are going to create an X image file called attributes that X-amount.
This file is going to hold the attributes of our custom view.
So the first thing that we should do in order to create a custom view in Android is to create an XML
file that contains the attributes of our custom view.
So we should provide the attributes of our custom view inside another separate exemplified.
So let's see how we can do that.
So you open this race folder and then we have this the values for the open it and then you can see these
colors that exemplified this things that exemplify.
And this ties that exemplified.
So you're already familiar with all of these files here.
You know that the colors that exemplify contains the colors that we can use inside and other place of
our project.
We have these strings that exemplify what is used in order to internationalize our application or to
put straight resources here.
It is actually recommended to put string resources here inside this void and do not hard code stream
values when you want to specify a string value.
Inside your project for example you create a button and your heart code that the text of that spot in
the Android operating system or the Android system is going to warn you that do not use Harke hard coded
strings.
You can't just create a stream resource here inside these strings that is in a file and then you can
refer to this name inside where ever inside your double file or inside XML file wherever you want.
So it is actually recommended to use strings that on file and that we have these styles that example
file which contains this application.
So now let me close these files here.
So now we want to create another string and at the next MFI and put that fine inside the values for
them.
So right click on these values into here and then click on new and then the kind of values resource
file.
So here we need to specify the filename.
The filing is going to be my underlined custom underline view underline attributes.
So here just click on OK now that we have this file here you can see this resources tag.
So let's actually go inside these resources tag Lippi DoubleClick undisturbed in order to make this
area wider and let's put another tag inside these resources stack sort of an attack and just type in
here.
Declare a dash style level.
The name is going to be my tepi in my custom.
So let me close the stack.
Now we have this starting tag and this closing tag here.
So let's go inside is declare sailable tack and let's create attack here.
Let's say that we have a TTR attribute which stands for attributes.
And now we need to specify the name of our attributes.
As you can see it is required.
So choose this one.
So the name is going to be your view color and then when it is specified the format of our actually
of our attributes.
So the format is going to be of type color as you can see if we have different formats here we have
Boulia format color dimension in our flag float fraction integer reference and string.
So here we want to choose color and then just self close the stack here by just putting in slash here.
Now let's create another attribute.
So just open a tad 83 on this one but the name is going to be text color ok text color.
And now we want to specify the format of our attributes.
So here again it is colored.
So we want to choose color as the format.
So again this self-enclosed stack.
Finally you've want to specify a text for our view so we can again open it like attribute.
The name is going to be text or view text view text and the format is going to be of type strange because
it is going to be the text.
And again let's self-enclosed this text if you want to you can add some more attributes here.
But now I recommend that you only put these attributes here until end.
So after you have actually finished creating this application you can manipulate this app you can manipulate
these attributes and create your own style or your own custom views.
And right now let's actually open the Android view.
So now that we created this XML file in order to specify the attributes of our actually our custom view
now we're going to create another class a class that is going to respond to these attributes.
As you can see here we said name my custom view.
So the class that you're going to create is the name of the class is going to be exactly the same as
this one.
My custom view.
So open the Android view here in the Java folder.
And here we have this first package.
Right click on this page.
New Java class.
So let's specify the name of the class the name of the class is going to be.
I told you to see exactly the same as this name.
My custom
and here are just click on OK.
Now this class is going to extend the view class so as you can see it's showing us an error here but
I'm going to solve this error in a moment.
But let's actually switch this might cause do you attribute the rest in a file.
So here we put this name here right.
So let's actually did it this way.
And let's again just type in here.
My custom view as you can see now that I'm actually typing this name it is referring to this class that
we created inside this package.
And you can see it's it's common example that Matas saw that.
This is the same package that we have here.
So let's choose this one and and present it on your keyboard.
In order to specify that we are exactly exactly referring to this class.
My custom view.
Now let's go to our custom view the job of fine.
Let's go inside this class in order to solve this error you need to create a constructor for this class
so the constructor is going to be actually Puplick and the name of the constructor is going to be my
custom view.
Put a pair of parenthesis here.
Let's open and closed this constructed by using this curly braces.
Now let's go inside the practices of this constructor.
And if you want to specify two privateer's here the first one is going to be a type context.
So the name is going to be context comma.
The second one is going to be have the attributes set.
So the name is going to be attributes set.
Now let's go inside this constructor and here as you can see is shown as an error.
If I hover over this entire area it says there is no default constructor available in and right that
view that view.
This means that we need to call this Super constructor of our custom class.
So the superclass is the view class right.
Here we are actually explicitly specifying that this might be a class is extending from the view class.
So we need clean say this constructed animated.
We need to say super and enter into the apprentice's we need to refer to our context come up and attribute
sets.
Now the error is gone.
So I think that's enough for this year to Oriol in the next tutorial.
We're going to completely implement this my custom view constructor inside is my custom view class.
So thank you very much for watching.
If you have any questions about this concept please post the discussion in the course and then I do
my best to answer all of your questions.
And I look forward to seeing you in the next tutorial.