Mobile Dev.
07/20/2022, 9:36 PMwindowManager = getSystemService(WINDOW_SERVICE) as WindowManager
val inflater = baseContext.getSystemService(LAYOUT_INFLATER_SERVICE) as LayoutInflater
floatView = inflater.inflate(R.layout.floating_layout, null) as ViewGroup
webView = floatView.findViewById(R.id.webView)!!
LAYOUT_TYPE = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
} else {
WindowManager.LayoutParams.TYPE_TOAST
}
floatWindowLayoutParams = WindowManager.LayoutParams(
150.toPx(baseContext),
200.toPx(baseContext),
LAYOUT_TYPE!!,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT
)
floatWindowLayoutParams.gravity = Gravity.CENTER
floatWindowLayoutParams.x = 0
floatWindowLayoutParams.y = 0
windowManager.addView(floatView, floatWindowLayoutParams)
and when i want to start the view
btnWebView.setOnClickListener {
startService(Intent(this, FloatingWindowApp::class.java))
}
Can you help me ?