Android uses WindowManager to generate floating buttons and floating menus

brief introduction

This paper imitates the basic effect of 360 mobile guard, and will supplement some principle knowledge of WindowManager later.

Overall thinking

The memory ball of 360 mobile guard is actually an application without a picture. The main body of the whole application is a service. After our program starts, start a service and close the activity at the same time:

We should note that the traditional service runs in the UI thread by default, which is different from the intentservice encapsulating a thread and handler, so we can directly change the UI related content in the service.

Let's take another look at the methods in floatwindowmanager:

And customized view:

In addition to loading a layout, the custom view is equipped with a touch listener to click the floating window pop-up menu. Note that view. Getlayoutparams () should be used here to obtain the width and height of the view. Because the view is not completed by measure in the construction method, the width and height obtained by using view. GetHeight is 0.

The method of creating a menu is similar. You can also use WindowManager:

The customized menu sets the background to be translucent and is divided into upper and lower parts. Click to delete the menu in the upper part and some displayed contents in the lower part:

It can be seen that the suspended window is actually implemented through windowsmanager.addview, and the type of layoutparam is set to type_ Phone, so your view is a system level view, which can cover the top of all programs. The rest is more about the knowledge of custom view.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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
分享
二维码
< <上一篇
下一篇>>