Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Custom Toast in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 192
    Comment on it

    Android give facility to change the view of a Toast. Sometimes we need to show message on a better way to user .

    Here I am writing code to implement custom Toast. I make a separate layout for Toast . Here I am showing a ImageView and TextView on a toast and Inflate it on toast . We can set gravity and Orientation here.

    custom_toast_layout.xml

    ?<xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:orientation="vertical" >
    <ImageView 
        android:id="@+id/custom_image"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/user_icon"
        />
    <textview android:id="@+id/custom_text" 
         android:layout_height="wrap_content" 
         android:layout_width="wrap_content" 
         android:text="Hello......Got it."
         android:layout_margintop="20dp" 
         android:layout_marginleft="10dp" 
         android:layout_torightof="@+id/custom_image">
    /RelativeLayout>
    
    
    
    View toastView=getLayoutInflater().inflate(R.layout.custom_toast_layout, null);
    
    Toast toastView=new Toast(this);
    customtoast.setView(toastView);
    customtoast.setGravity(Gravity.CENTER_HORIZONTAL);
    customtoast.setDuration(Toast.LENGTH_SHORT);
    customtoast.show();
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: