Center a Toast - Android User Interface

Android examples for User Interface:Toast

Description

Center a Toast

Demo Code


//package com.java2s;
import android.content.Context;

import android.view.Gravity;
import android.widget.Toast;

public class Main {
    public static void toastCenter(Context context, String text,
            boolean isLong) {

        Toast toast = Toast.makeText(context, text,
                isLong ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();// w  w w  . ja v  a2  s. c  om

    }
}

Related Tutorials