Toast Class
Toast class is used to show notification for a particular
interval of time. After sometime it disappears. It doesn’t block the user
interaction.
Constants of Toast Class
There are only 2 constants of Toast class which are given
below.
Constant
|
Description
|
Public
static final int LENGTH_LONG
|
displays
view for the long duration of time.
|
Public
static final int LENGTH_SHORT
|
Displays
view for the short duration of time.
|
Methods
of Toast class
The widely used method of Toast class are given below.
Method
|
Description
|
Public
static Toast makeText(Context context, CharSequence text, int duration)
|
Makes the
toast containing text and duration.
|
Public void
show().
|
Displays
|
Public void
setMargin(float horizontalMargin,float verticalMargin)
|
Changes the
horizontal and vertical margin difference.
|
Public void
setGravitiy(Gravity.LEFT,0,0)
|
Change the
gravity of the Toast
|
Android
Toast Example
Toast.makeText(getApplicationContext(),”Hello Android is simples”,Toast.LENGTH_SHORT).show().
Another
Code:
Toast toast=Toast.makeText(getAplicationContext(),”Hello
Android is Simles”,Toast.LENGTH.SHORT);
Tast.setMargin(50,50);
Toast.show();
Here, getAplicationContext() method return the instance of
Context.
No comments:
Post a Comment