java android show toast
Toast myToast = Toast.makeText(this, "I'm a toast!", Toast.LENGTH_LONG);
myToast.show();
java android show toast
Toast myToast = Toast.makeText(this, "I'm a toast!", Toast.LENGTH_LONG);
myToast.show();
android studio make toast appear at top of screen
// v is the Button view that you want the Toast to appear above
// and messageId is the id of your string resource for the message
private void displayToastAboveButton(View v, int messageId)
{
int xOffset = 0;
int yOffset = 0;
Rect gvr = new Rect();
View parent = (View) v.getParent();
int parentHeight = parent.getHeight();
if (v.getGlobalVisibleRect(gvr))
{
View root = v.getRootView();
int halfWidth = root.getRight() / 2;
int halfHeight = root.getBottom() / 2;
int parentCenterX = ((gvr.right - gvr.left) / 2) + gvr.left;
int parentCenterY = ((gvr.bottom - gvr.top) / 2) + gvr.top;
if (parentCenterY <= halfHeight)
{
yOffset = -(halfHeight - parentCenterY) - parentHeight;
}
else
{
yOffset = (parentCenterY - halfHeight) - parentHeight;
}
if (parentCenterX < halfWidth)
{
xOffset = -(halfWidth - parentCenterX);
}
if (parentCenterX >= halfWidth)
{
xOffset = parentCenterX - halfWidth;
}
}
Toast toast = Toast.makeText(getActivity(), messageId, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, xOffset, yOffset);
toast.show();
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us