First, the goal
Sets the display position of the Custom Toast window (1–2);
Second, the Code implementation
1. In the "Show Number Attribution" Service (Showphoneaddservice) class, in the custom Toast (Mytoast) method, The Gravity property of the Window object Windowmanager.layoutparams (params) allows you to set the alignment of a custom toast (top: gravity.top, Upper-left corner: gravity.top+ Gravity.left);
2. The X property of the Window object Windowmanager.layoutparams (params) allows you to set the position of a custom toast in the x-axis of the phone window (note: The default gravity (center) property that requires a custom toast when using this property is ignored when using the Gravity.LEFT , Gravity.START , Gravity.RIGHT ,Gravity.END等对齐方式时,该属性表示与给定对齐方式的边界的偏移量,即当为LEFT时x值表示自定义Toast窗口左边与左边界的偏移量,当为RIGHT时x值表示自定义Toast窗口右边与右边界的偏移量);窗口对象WindowManager.LayoutParams(params)的y属性也是如此。
Set the custom Toast window display Location Code:
1 params.gravity = gravity.top + gravity.left; // set the Toast window to align to the upper-left corner 2 Params.x = 50; // sets the offset of the left edge of the toast window from the left border of the screen window to 50 pixels 3 Params.y = 50; // sets the offset of the top edge of the toast window from the upper boundary of the screen window to 50 pixels
View Code
Android instance-Mobile security Defender (42)-Set Custom toast location