Introduction to the

A draggable application outside suspension window

FloatWindow warehouse

integration

Step 1: Add the following to your project’s build.gradle:

allprojects {
    repositories {
        google()
        jcenter()
        mavenLocal()
    }
}
Copy the code

Step 2: Add the following to build.gradle:

Dependencies {implementation 'com. Youer. UI: floatwindow: 1.0.0'}Copy the code

use

  • Support drag

  • Permission application is automatically performed internally

  • Supports setting percentages of position and width and height

  • Supports status monitoring, such as permission application result and location

Based on using

FloatWindow = new Builder(this, floatView).setwidth (screen.width, 0.5f).setheight (screen.height, 0.3 f). SetStartX (Screen WIDTH, 0.5 f). SetViewStateListener (viewStateListener). SetPermissionListener (floatPermissionListener). The build (); floatWindow.show();Copy the code

Update View State

/ / show floatWindow. The show (); / / close floatWindow. Dismiss (); / / update position floatWindow. UpdateLocation (100200); // Set to editable (editable external click does not respond) floatWindow.seteditable (true);Copy the code

Problems encountered

  1. Layoutparams. gravity can only be set to gravity.start

Gravity can be set to a different location, causing a drag error. If gravity is set to a different location, you can only change the x and y of layoutParams

  1. Popover input box cannot be edited

Default layoutParams suspended the window flag set is WindowManager layoutParams. FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;

In this case, the outside of the window can respond to clicks, but the inside can’t get focus, so the input box can’t be pulled up.

I didn’t find a good solution, so the current solution is to add an Editable state and leave FLAG_NOT_FOCUSABLE unenabled

Reference documentation

Android suspension window read this article enough

FloatWindowUtils

All kinds of flag meaning of the WindowManager. LayoutParams

other

Publish modules to Maven

Android Skill tree lighting project Git library

Android Skill Tree Lighting plan – Sparrow document library

Rare earth mining: You two

Making: PettyWing