Toast in Android.

 Toast in Android.  /   SNACKBAR/(for permanent display notification can be used)sdfsdf/

Toast.makeText(MainActivity.this, "login Successfully", Toast.LENGTH_SHORT).show();

Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;

Toast toast = Toast.makeText(context, text, duration);
toast
.show();


FOR STYLEABLE TOAST 
  • First implement latest dependency.
  • dependencies { implementation 'io.github.muddz:styleabletoast:2.4.0' }
  • Next, go to values -> style -> create new <style name = "signuptoast"> layout
  • <style name="signupToast">

    <item name="stColorBackground">#228B22</item>
    <item name="stTextBold">true</item>
    <item name="stTextColor">#fff</item>
    <item name="stFont">@font/retrofont</item>
    <item name="stTextSize">14sp</item>
    <item name="stColorBackground">#fff</item>
    <item name="stSolidBackground">true</item>
    <item name="stStrokeWidth">3dp</item>
    <item name="stStrokeColor">#fff</item>
    <item name="stIconStart">@drawable/ic</item>
    <item name="stIconEnd">@drawable/ic</item>
    <item name="stLength">LONG</item> LONG or SHORT
    <item name="stGravity">top</item> top or center
    <item name="stRadius">5dp</item>
    </style>
  • in Java
  • StyleableToast.makeText(MainActivity2.this, "Hello World!", Toast.LENGTH_LONG, R.style.signupToast).show();

new StyleableToast .Builder(context) .text("Hello world!") .textColor(Color.WHITE) .backgroundColor(Color.BLUE)
.show();
     Toast t = Toast.makeText(getApplicationContext(),
                                         "This a positioned toast message",
                                         Toast.LENGTH_LONG);
                t.setGravity(Gravity.BOTTOM | Gravity.RIGHT, 0, 0);
                t.show();









Comments

Popular posts from this blog

the distance between two cities (in km is input through the keyboard. write a program to convert and print this distance in meter ,feet inches and centimeter.

CREATE UNIT CONVERTER APP

write a program to check whether a triangle is valid or not, when the threeangles of the triangle are entered through the keyboard. A triangle is valid if the sumof all the three angles is equal to 180 degrees