-
-
Save pavan5208/6301f9f838ff1dbaf878d1ebba3312a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun addFloatingMenu() { | |
if (floatingControlView?.parent == null) { | |
//Set layout params to display the controls over any screen. | |
val params = WindowManager.LayoutParams( | |
WindowManager.LayoutParams.WRAP_CONTENT, | |
WindowManager.LayoutParams.WRAP_CONTENT, | |
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) WindowManager.LayoutParams.TYPE_PHONE else WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, | |
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, | |
PixelFormat.TRANSLUCENT | |
) | |
params.height = dpToPx(50) | |
params.width = dpToPx(50) | |
iconWidth = params.width | |
iconHeight = params.height | |
screenHeight = windowManager?.defaultDisplay?.height?:0 | |
screenWidth = windowManager?.defaultDisplay?.width?:0 | |
//Initial position of the floating controls. We can customize things here | |
params.gravity = Gravity.TOP or Gravity.START | |
params.x = 0 | |
params.y = 100 | |
//Add the view to window manager | |
windowManager?.addView(floatingControlView, params) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment