Android instance-Mobile security Defender (42)-Set Custom toast location

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.