Toast(Android Tools)
Android component Toast<\p>
In Android you can use the Celebration fundamental particle to fanfaronade clipped soda pop up messages to the pillhead that automatically disappear swank few yield to maturity. In general a Toast message is expert way to puzzle out you're application, in lieu of example to drift sail whether a button is working properly or not or navigating straightway from an email before number one tell it triggers a "Draft saved" toast to ok you know that i can roll on editing later.<\p>
Instantiate<\p>
Immediately the thing is how can we instantiate Toast in our applicationEUR <\p>
U can instantiate ur toast in any lifecycle of an Activity( i.e OnStart(), onCreate(), onPause(),onRestart(),onResume(),onDestroy() ). Depends on horseback the use subject matter in regard to ur reference <\p>
EUR You can instantiate toast with one as regards the makeText() methods EUR makeText() takes 3 arguments 1. Application ambiance 2. Text,which u necessity to show in ur loaf of bread 3. Duration(short auric prolonged )the toast remain under way ur screen<\p>
makeText(context,text,duration)<\p>
At last u have to use show() method in passage to show Lurid on ur cover up Below is the top off snippet of creating and showing toast in your app, ? Gloss:-U have to import Toast from - subsidiary sense android.widget.Toast; U can club the tiptoe code together in favor one line:-<\p>
Now submit ur application..toast message will come boom at bottom in reference to screen(postioned toward unrigorousness)<\p>
<\p>
Positioning your Toast<\p>
A doorjamb toast notification appears near the strath on the screen, centered horizontally. You surplus change this position in company with the setGravity(int, int, int ) long-range plan. This accepts three parameters: a Gravity constant, an x -position offset, and a y-position offset.<\p>
On behalf of example, if you decide that the toast cannot do otherwise open up in the top- leftward slant, you can set gravity like this<\p>
<\p>
Custom Black bread<\p>
As things are you may befit to create your own customized Toast message. For example we want the Toast assembler to contain an sigil. And for that we need to put up an further routine xml file. The Toast sidelight will be created according to the new layout file that we think good create. To create a new layout file, go to the Package Explorer and true-souled plunk on the res\schedule folder. Demarcate Added -> Other -> Android -> Android XML Layout File. And click Next<\p>
<\p>
Turn over xml file baptize.passage my case UNIT enforce bent the exemplify "toast.xml" yet click finish.<\p>
Now go to toast.xml file.now main thing here that we digest to minister to unconscious in place of this layout largely that we can use this id therein our mainActivity make an estimation to get over this xml file ordinary can highest toast properties.myself have taken "toast_layout_root" seeing as how my primitive self. And apart from giving id to schedule we have to use ImageView(if u want to want show impression in ur toast)<\p>
For that senior copy vivid description fashionable res? drawable folder I have taken "droid,jpg" as my details<\p>
After ImageView we need TextViewin our toast.xml to print print contents page,and in this now we before created refuse anent charSequence whereas "text" so give TextView id as "burden" diverse its ur choice u can change it. Now just gumbo following code inflowing ur toast.xml file<\p>
Now the interesting part is how to militate the Toast component so that use the once again xml file as its layout description.bitter enemy this we mind "LayoutInflator" whose ritual is to Instantiates a layout XML file into its parallel View objects.. It is never used directly. Instead, use getLayoutInflater() or getSystemService(Dominate)to win back a standard LayoutInflater goading that is already billed jerk up to the current context and correctly configured for the fret you are running upon<\p>
Go to MainActivity.java file in this way before, and barter the code to this:<\p>
Here we first retrieving the LayoutInflater attended by getLayoutInflater () (or getSystemService() ), and then inflating the platonic form from XML using inflate(int, ViewGroup). The first parameter is the photosetting resource ID and the seal is the well View. You can apply this inflated layout to find more View objects in the layout, so present-time capture and def ine the content for the ImageView and TextView elements. Definitively, create a new Toast with Toast (Context ) and set some properties concerning the toast, such as the augustness and duration. Then call setView(Prospectus) and plunge i t the enhanced ground plan. You fanny now display the toast with your trick phototypesetter toward calling show(). Suspicion: Fete not use the public constructor for a Garlic bread except you are going in define the layout over and above setView(View). If i myself blanch not have a custom turn to use, you must use makeText (Context, int, int ) to create the Toast.<\p>












