Last active
December 27, 2015 09:49
-
-
Save ChrisRisner/7306976 to your computer and use it in GitHub Desktop.
Different ways of showing toasts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Toast.makeText(this, "This is a toast that isn't centered in anyway at all", Toast.LENGTH_SHORT).show(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Toast toast = Toast.makeText(this, "This is a toast that is centered onscreen and the text is centered in the toast", Toast.LENGTH_SHORT); | |
LinearLayout layout = (LinearLayout) toast.getView(); | |
if (layout.getChildCount() > 0) { | |
TextView tv = (TextView) layout.getChildAt(0); | |
tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL); | |
} | |
toast.setGravity(Gravity.CENTER, 0, 0); | |
toast.show(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Toast toast = Toast.makeText(this, "This is a toast where the text is centered in the middle of the toast", Toast.LENGTH_SHORT); | |
LinearLayout layout = (LinearLayout) toast.getView(); | |
if (layout.getChildCount() > 0) { | |
TextView tv = (TextView) layout.getChildAt(0); | |
tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL); | |
} | |
toast.show(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Toast toast = Toast.makeText(this, "This is a toast that is centered onscreen but the text isn't centered", Toast.LENGTH_SHORT); | |
toast.setGravity(Gravity.CENTER, 0, 0); | |
toast.show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment