android-target-tooltip icon indicating copy to clipboard operation
android-target-tooltip copied to clipboard

Positioning Issue: Tip Window appear to be more bottom on Android 11

Open samuelchou opened this issue 4 years ago • 6 comments

Run the demo app on Google Pixel 5(Android 11) and you will see what similar to below. The ToolTip position seems to be more "bottom" than expected.

device-2020-12-21-150319

I'm sure that is not related to night theme, and not even related to gravity.

device-2020-12-21-151245

I don't know if this is related to Pixel (5) or Android 11, though.

samuelchou avatar Dec 21 '20 07:12 samuelchou

using AVD Pixel 3a API 30 x86 can cause similar problem.

device-2020-12-21-154752

samuelchou avatar Dec 21 '20 07:12 samuelchou

Android 8 and Android 10 cannot re-produce the issue, no matter what device it is. I guess the problem comes along with Android 11 (API 30)

samuelchou avatar Dec 21 '20 08:12 samuelchou

Facing the same issue on Google Pixel 2 XL (Android 11)

Found any solution @samuelchou ?

amarilindra avatar May 04 '21 08:05 amarilindra

So I banged my head against this issue, it seems to only be happening on Android 11 (not on Android 12).

Looks like you need to subtract the status bar height to get it aligned correctly.

val tooltip = Tooltip.Builder(context).anchor(this, 0, determineYOffset(context), true)

private fun determineYOffset(context: Context): Int =
          if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R)
              -((context as? MainActivity)?.statusBarHeight ?: 0)
	else
              0

SeanBlahovici avatar May 29 '21 04:05 SeanBlahovici

Also, it looks like if the device has a notch/cut out, you need to compensate for its height as well. Based on the example above:

private fun determineYOffset(context: Context): Int =
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {
        val activity = context as? MainActivity
        val statusBarHeight = activity?.statusBarHeight ?: 0
        val cutoutHeight = activity?.window?.decorView?.rootWindowInsets?.displayCutout?.safeInsetTop ?: 0
        cutoutHeight - statusBarHeight
    } else {
        0
    }

zarsky avatar Aug 18 '21 23:08 zarsky

@zarsky When I tested out your method on a device with a notch the cutoutHeight was equal to statusBarHeight which made yOffset 0 again. Can you specify for which case you needed cutoutHeight as well? Also, I got statusBarHeight using the following method.

val metrics: WindowMetrics = activity.windowManager.currentWindowMetrics
val insets = metrics.windowInsets.getInsets(WindowInsets.Type.statusBars())
val statusBarHeight = insets.top

ankuratdunzo avatar Nov 04 '22 12:11 ankuratdunzo