Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Example of toast prompt in android

Shulou Source: shulou.com Published: 2022-06-02 14:15:13 10月01日 Update

This article mainly introduces examples of toast tips in android. The article is very detailed and has certain reference value. Interested friends must read it!

Toast prompt is a message box type in Android system, a simple message prompt box, is a mechanism used to display prompt information in Android; the idea of Toast class is to be as inconspicuous as possible, while still displaying information to the user.

Toast tips in android

Toast prompt is a message box type in Android system, a simple message prompt box; it is a mechanism used to display prompt information in Android.

When the view is displayed to the user, it appears floating in the application. Unlike Dialog, it never gains focus and cannot be clicked on. The user will probably be typing something else in the middle.

The idea behind Toast is to be as unobtrusive as possible, while also presenting information to users that they want them to see. And Toast display time is limited, Toast will automatically disappear according to the display time set by the user.

Here's an example of how to use Toast:

Default Style: Toast.makeText (getApplicationContext(), "Default Toast Style",Toast.LENGTH_SHORT).show(); Custom Display Position: toast = Toast.makeText (getApplicationContext(),"Custom Location Toast", Toast.LENGTH_LONG);toast.setGravity (Gravity.CENTER, 0, 0);toast.show(); with picture effects: toast = Toast.makeText (getApplicationContext(),"Toast with pictures", Toast.LENGTH_LONG);toast.setGravity (Gravity.CENTER, 0, 0);LinearLayout toastView =(LinearLayout) toast.getView();ImageView imageCodeProject = new ImageView (getApplicationContext());imageCodeProject.setImageResource (R.drawable.icon);toastView.addView (imageCodeProject, 0);toast.show(); fully customized: LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate (R.layout.custom,(ViewGroup) findViewById (R.id.llToast));ImageView image =(ImageView) layout.findViewById (R.id.tvImageToast);image.setImageResource (R.drawable.icon);TextView title =(TextView) layout.findViewById (R.id.tvTitleToast);title.setText ("Attention");TextView text =(TextView) layout.findViewById(R.id.tvTextToast);text.setText("Fully Custom Toast");toast = new Toast(getApplicationContext());toast.setGravity(Gravity.RIGHT| Gravity.TOP, 12, 40);toast.setDuration(Toast.LENGTH_LONG);toast.setView(layout); toast. show (); The above is "Example of toast prompt in android" All the contents of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!

Tags: Tips users information messages examples usage location content at the same time pictures that is as much as possible attention ideas time mechanisms styles simplicity articles types Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology macOS Redmi Microsoft Shulou Tech Info