app/src/main/java/fr/neamar/kiss/CustomIconDialog.java
/**
         * @param v       is the Button view that you want the Toast to appear above
         * @param message is the string for the message
         */
@param v       is the Button view that you want the Toast to appear above
@param message is the string for the message
@param v is the Button view that you want the Toast to appear above @param message is the string for the message
private void displayToast(View v, CharSequence message) {
            int xOffset = 0;
            int yOffset = 0;
            Rect gvr = new Rect();
            if (v.getGlobalVisibleRect(gvr)) {
                View root = v.getRootView();
                int halfWidth = root.getRight() / 2;
                int halfHeight = root.getBottom() / 2;
                int parentCenterX = (gvr.width() / 2) + gvr.left;
                int parentCenterY = (gvr.height() / 2) + gvr.top;
                if (parentCenterY <= halfHeight) {
                    yOffset = -(halfHeight - parentCenterY);
                } else {
                    yOffset = (parentCenterY - halfHeight);
                }
                if (parentCenterX < halfWidth) {
                    xOffset = -(halfWidth - parentCenterX);
                }
                if (parentCenterX >= halfWidth) {
                    xOffset = parentCenterX - halfWidth;
                }
            }
            Toast toast = Toast.makeText(v.getContext(), message, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, xOffset, yOffset + v.getHeight());
            toast.show();
        }
private void displayToast ( View v , CharSequence message ) { int xOffset = 0 ; int yOffset = 0 ; Rect gvr = new Rect ( ) ; if ( v . getGlobalVisibleRect ( gvr ) ) { View root = v . getRootView ( ) ; int halfWidth = root . getRight ( ) / 2 ; int halfHeight = root . getBottom ( ) / 2 ; int parentCenterX = ( gvr . width ( ) / 2 ) + gvr . left ; int parentCenterY = ( gvr . height ( ) / 2 ) + gvr . top ; if ( parentCenterY <= halfHeight ) { yOffset = - ( halfHeight - parentCenterY ) ; } else { yOffset = ( parentCenterY - halfHeight ) ; } if ( parentCenterX < halfWidth ) { xOffset = - ( halfWidth - parentCenterX ) ; } if ( parentCenterX >= halfWidth ) { xOffset = parentCenterX - halfWidth ; } } Toast toast = Toast . makeText ( v . getContext ( ) , message , Toast . LENGTH_SHORT ) ; toast . setGravity ( Gravity . CENTER , xOffset , yOffset + v . getHeight ( ) ) ; toast . show ( ) ; }
@param v       is the Button view that you want the Toast to appear above
 @param message is the string for the message
@param v is the Button view that you want the Toast to appear above @param message is the string for the message
//View parent = (View) v.getParent(); //int parentHeight = parent.getHeight();