Dark Horse programmer --- mobile guard day4 custom toast, dark horse day4
Custom toast
First, obtain a window manager.
WindowManager wm = (WindowManager) getSystemService (WINDOW_SERVICE );
Wm isFull ScreenOnly the view is displayed in the window.
Bind a view and window parameter params in the window manager to generate a display of the view content.
Wm. addView (view, params );
Example:
<Span style = "white-space: pre"> </span> view = View. inflate (this, R. layout. address_show, null); TextView textview = (TextView) view. findViewById (R. id. TV _address); // "Translucent", "active orange", "Wei Shi blue", "metallic gray", "apple green" int [] ids = {R. drawable. call_locate_white, R. drawable. call_locate_orange, R. drawable. call_locate_blue, R. drawable. call_locate_gray, R. drawable. call_locate_green}; SharedPreferences sp = getSharedPreferences ("config", MODE_PRIVATE); view. setBackgroundResource (ids [sp. getInt ("which", 0)]); textview. setText (address );
// WindowManager is set for the form parameters. layoutParams params = new WindowManager. layoutParams (); params. height = WindowManager. layoutParams. WRAP_CONTENT; params. width = WindowManager. layoutParams. WRAP_CONTENT; params. flags = WindowManager. layoutParams. FLAG_NOT_FOCUSABLE | WindowManager. layoutParams. FLAG_NOT_TOUCHABLE | WindowManager. layoutParams. FLAG_KEEP_SCREEN_ON; params. format = PixelFormat. TRANSLUCENT; params. type = WindowManager. layoutParams. TYPE_TOAST; wm. <strong> addView </strong> (view, params );
Code registration Handler
<Span style = "white-space: pre"> </span> // use the code to register the broadcast receiver: new outcallemedier (); // intent filter <strong> IntentFilter </strong> filter = new IntentFilter (); // specify the behavior filter to be filtered. <strong> addAction </strong> ("android. intent. action. NEW_OUTGOING_CALL "); // (Register) bind the action to the aggreger <strong> registerReceiver </strong> (aggreger, filter );