Android implements system level hover buttons

This example shares the specific code of Android system level suspension button for your reference. The specific contents are as follows

Specific needs

1. It is to make a system level floating button, just like the floating button on the iPhone desktop. It can be dragged at will, and as soon as you release your hand, the floating button will automatically lean to the side. 2. You can click and drag at will. 3. When the hover button automatically moves to the side, or moves to the side, it automatically hides half of the side. 4. Both horizontal and vertical screen switching are compatible

1. Add a view in WindowManager, which is implemented through custom controls. 2. Motionevent.action in ontouch_ In the move event, you can move freely by controlling the specific coordinates of the suspension button. 3. Motionevent.action in ontouch_ In the up event, you can control the levitation button to automatically lean to the side and automatically hide half of the side. However, here, ontouch and onclick are triggered together, but there are also solutions. You can decide whether to trigger the click event by moving the distance at the moment of releasing your hand. If false is returned, the click event will be triggered, If true is returned, the click event will be triggered. 4. Capture the horizontal and vertical screen switching event through the user-defined control onlayout method. 5. There is also a problem about which side to dock. Judge which side is closer through coordinates. Stop on which side! [draw a square with the shorter X axis based on the center point in the middle]

The following is the specific implementation code:

Call the implementation code. Here is a problem. The system level floating window pops up. You need to configure permissions:

In addition, for mobile phones above Android 6.0, a dialog box will pop up to ask the user whether it is running. If the user refuses, the system level suspension window will not pop up. Some mobile phone manufacturers have modified the Android source code, and need to enter the system settings to allow the application to pop up the suspension window. In this way, the experience is very bad, but here is a trick. Set it to toast type in the following way to completely solve the problem. There is no need to configure permissions or pop-up windows to obtain permissions from users, so as to completely solve the problem.

The specific implementation code is as follows:

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