[Android] mobile guard custom toast

Continue to add the member method mytoast() in the addressservice, which was used to listen for incoming calls

Get the textview object, new, and construct the parameter: context object

Call the settext() method of the textview object to set the text

Call settextsize() method of textview object to set the size. Parameter: int

Call the settextcolor() method of the textview object to set the color

Get WindowManager object, call getsystemservice() method, parameter: Windows_ SERVICE

Call the addview() method of the WindowManager object and add it to the view. Parameters: view object, windowmanager.layoutparams object

The setting of layoutparams object refers to the show() method of toast class

At this time, the view will be displayed for making and receiving calls, but it cannot be eliminated

In the previous method of judging incoming calls, monitor the idle state of the phone and remove this view

Add telephonymanager.call to switch judgment_ STATE_ IDLE

Judge whether the textview object is empty

Call the removeview() method of WindowManager object. Parameters: view object (textview added above)

Using layout files

Create a new layout file address_ toast.xml

Linear layout, horizontal arrangement, one ImageView, one textview, textview definition ID

In the method of customizing toast

Call the view. Inflate() method to obtain the view object. Parameters: context, resource file, null

Just add this view

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>