Home>
I do n’t know if all the guest officers find the system toast information ugly.The default but black background,No color.
Then I will teach you the simplest way to customize the toast layout.
First load a custom layout
layoutinflater inflater=context.getlayoutinflater ();
view view=inflater.inflate (r.layout.toast_info, null);
Then find the controls inside,Take pure textview as an example
textview txt=(textview) view.findviewbyid (r.id.txt_tips);
The next step is to set the information for the textview.
txt.settext (info);
The most important thing is the following,Reference layout toast
Get toast:
toast toast=new toast (context);
Set the toast display position:
toast.setgravity (gravity.center_horizontal | gravity.bottom, 0, 80);
Set the pop-up time:
toast.setduration (time);
Set the layout:
toast.setview (view);
last step,show it out:
toast.show ();
Dear! Isn't it simple?In the future, you can use the handsome toast information.Far from the dwarf,This is the goal of our struggle
Related articles
- Super simple implementation of Android custom Toast example (with source code)
- Android custom Toast display time
- Android programming classic code collection (copy, paste, browser call, Toast display, custom Dialog, etc)
- Android Toast custom display time
- Summary of Android Development Methods for Obtaining LayoutInflater Objects
- Android LayoutInflater loading layout detailed and example code
- LayoutInflater example of Android layout loading
- Android development implements custom Toast, LayoutInflater using other layout examples
Trends