Today, I saw an application pop-up toast, and it seems pretty good to have a sound. I said you don't have to fight, so come and say toast.
No,CodeOffer:
Package Weibo. lixiaodaoaaa. view; import Weibo. lixiaodaoaaa. UI. r; import android. content. context; import android. media. mediaplayer; import android. util. displaymetrics; import android. view. gravity; import android. view. layoutinflater; import android. view. view; import android. widget. textview; import android. widget. toast;/*** toast custom toast controls with audible prompts ** @ author http://weibo.com/lixiaodaoaaa http://t.qq.com/lixia Odaoaaa * @ version 0.1 * @ created 2013-4-23 */public class mytoast extends toast {private mediaplayer mplayer; private Boolean issound; Public mytoast (context) {This (context, false );} // issound indicates whether to play music; Public mytoast (context, Boolean issound) {super (context); this. issound = issound; mplayer = mediaplayer. create (context, R. raw. allsuccess); mplayer. setoncompletionlistener (ne W mediaplayer. oncompletionlistener () {@ override public void oncompletion (mediaplayer MP) {MP. Release (); // release resources. Release resources;});} @ override public void show () {super. show (); If (issound) {mplayer. start () ;}}/*** set whether to play the sound */Public void setissound (Boolean issound) {This. issound = issound ;} /*** get the control instance ** @ Param context * @ Param text * prompts the message * @ Param issound * Whether to play the sound * @ return */public static mytoast show (context, charsequence text, Boolean issound, int duration) {mytoast result = new mytoast (context, issound); layoutinflater inflate = (layoutinflater) context. getsystemservice (context. layout_inflater_service); displaymetrics dm = context. getresources (). getdisplaymetrics (); view v = inflate. inflate (R. layout. new_data_toast, null); // v. setminimumwidth (DM. widthpixels); // set the minimum widget width to the mobile phone screen width textview TV = (textview) v. findviewbyid (R. id. new_data_toast_message); TV. settext (text); result. setview (V); result. setduration (duration); // set the display duration; result. setgravity (gravity. bottom, 0, (INT) (DM. density * 85); return result ;}}
The display effect is as follows:
Download the demo of the test project (Demo download) and click here to download it.