So Hello Youtube Its me Priyank
and in this video we are going to talk about
toast messages, So there are
some notifications that pop from below
and those are like the black
notifications that we get below our application
in the bottom part of the phone and
We will be talking about toast applications, we will be making our
applications
that use toast notifications and
by the way in case you haven't yet subscribed then please hit the subscribe button
because this channel is all about programming and
and stuff like that
and I upload regular video. This course is
all about
Application development. We are making applications like
WhatsApp, Instagram and these videos
are completely free and for beginners
There is a complete playlist available
on my youtube channel. Go there and subscribe, like,
share and stuff like that
So Please Support me guys, Again its me priyank
Let's start the video without wasting time.
We will start by creating a new
application and the name of the application
as always will be toast and its an empty activity
In case you are new and you dont know whats going on
then this is something that is explained
in previous video.
How to create a new project in Android Studio
All the basics are already done and in case you have missed them
then please watch the complete playlist
So first of all we will
add a button and the text will be
create toast messages
actually the user should press this button
to see a toast message and
Let's add
a text - 'Show Toast'
So this is how the toast messages work
and will be shown. In few minutes ill show you
What are actually toast messages for now
Let's Just create
A function for the button
ill just create a function
So the name of the function will be 'login'
so you can actually change the name of the function
I have explained buttons in my previous videos
In case you have missed them then please
check all the videos in the playlist
Right now, I have just created a function
or a method called 'Login'
Which is a view method
We have added the libraries which are required
for view
In case you don't know - How to add libraries?
I have
actually explained them in my previous videos, you can
use keyboard shortcut. You can just right toast
and then create toast message. i.e. the second option.
I am going to select the second
then the text will come up
the text is usually
as you can see the libraries are added
this thing over here is
basically to show the toast message
inside the application and the text
that should be inside the toast should come in double quotes
Android Studio
does a pretty good job in
completing our sentence and one more important thing is LENGTH_LONG
LENGTH_LONG means bigger toast message
LENGTH_LONG / LENGTH_SHORT
It basically shows the message for longer
period of time
We will attach the function/method to the onClick even
event and we will play the application
to see if it works
So I have just tested the application.
We have created an App
which has a button and once the button is pressed
as you can see there is a toast message over here. So These
the toast messages - The little popups
that you get once your application
is running and there are notifications
in the bottom. So You can actually use toast
Toast notifications or Toast Messages
To actually provide information to the user
For shorter duration of time
The normal notification stays there
for longer duration of time whereas toast messages
go away in like few seconds or few miliseconds
This is how it actually works
The next thing that you have to
actually work around is
you can use this toast message
in case you want to notify
the user if he has done
any mistake or stuff like that
for example, ill add a text here
stating that what is your name
So this text will basically ask
the name of the user who is using and
over here he has to enter a name
but incase he enters something wrong
or something else
then he might get a notification that he should
enter proper name. So these are like minute
things that you have to take care and
you have to learn around. So as you can see
We will create some application which will take input
from the user and which will show
toast message and
show the toast message with the input
so we have a button, we have a layout and
we have a text field
A textview, A textfield and A button
this is what we have done in our previous videos
So what we are going to do is we are just
going to actually add
some more functionality to the button so right now
the button is actually showing a toast message
we will add some more functionality first of all
Ill use the edit text widget
and again you have to add in the library
by pressing the shortcut keys as you can see
I have added the libraries
and you can press the shortcut key, now we
have written a code
this code was actually used in our previous video
this line basically means we are
getting the text inside the textfield
and we are storing it in
inside variables. Now to make one thing clear
We have to add the resource ID i.e. ID i.e. in purple
and you can actually add that
now to add a text which is
To add a variable in toast message you have to
actually use
convert .toString() method
so ill just type in EditText.getText()
and this is something that we have used in our previous video
the toString() function
Don't worry in case you dont know what is going on
i'll be explaining everything in detail, you dont have to
worry about it. We will just print
the thing that is added by the user
So in the middle of the bracket
there is a bracket and on the right hand side we have
LENGTH_LONG and on left we have get.Text()
between them we have a :
,
So in between the , we have to add
what we have to print and right now we have just added
the message that is
actually taken from the user
so text = and we will just add
hello
see everything between two comma is
to be printed
inside the toast message ok
so what ever we right, if it is a text, we can
we can just use that and add a plus sign
add a variable and I hope this is clear
this is kind of confusing for new
people who are new to this channel and
are new to programming overall
dont worry ill be covering java later on
after few videos, for now you can just
write in the code and
In case you want to understand it logically
you can just understand that
the comma
there are two commas in
toast.make. See once we have made
so we have to actually add a text over here
and what you can do is you can actually
but inside this two commas you can
add stuff that you want to add. So incase you want to add stuff
something else like we are adding a
variable, you can do that and
Variables are basically containers that hold data
So I hope it is clear, variable is
holding the text that is added
and on the right hand side you can set
the timing like the popup should be
short or the popup should be long
you can play around with that and you can change short to long
and test various options
and there is a problem with the
I am . really sorry i missed it out and you can actually
add in the layout and you can link
all the elements to each other so this is
this is how it has to be done, you can actually
link them to each other and then to the constraints
as you can see we will stick everything together
and we will add a springy action
between them
as you can see there is a springy action so
the springy thing basically means it will
stick to the border and
it will stick to the border
as the resolution changes and as the
as the size of the screen changes, it will change
if we switch to a tablet or a pixel2 device
as you can see it actually changes
this is how it actually works and you have to use this
in your layout if you are developing applications
We have different devices because we dont
actually know how many android devices are
available in the market
what are the resolution of the
devices. So you can actually use this devices
this layout thing this springy thing to
to actually you know make it
responsive, responsive as in
once we change the
size of the screen, as you can see the button stays
there but
the text field changes its position
so you can do that and you can
you can actually add in a padding over here so
it will not stick to the screen directly
it will give some gap
you can actually add in some padding
by adding the numbers on the right hand side so if
add 16 and
if I add 16
as you can see there is a padding a margine
and you can do the s
same for the layout
this is how it actually works and it is quite
good because
once the change, once the screen
it will automatically move to center
adjust itself
to
according to the screen resolution so
I am really sorry that I have not
explained this in previous videos
but this time its
so ill just add in my name and ill click on
so its showing hello priyank so
this is how the app works. The name goes in
the container and then the container is printed
in toast message.
Không có nhận xét nào:
Đăng nhận xét