0

The code below works fine on Android 14-, but on Android 15, the bottom of the Tooltip is truncated:

truncated

The bottom of the red border is missing, and only the top part of the letter 'g' is visible.

Looks like it's missing the height of the top status bar, how to fix it? The code:

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()

        var veryLongTooltip = ""
        for (i in 0..60) { // generate 60 lines
            veryLongTooltip += "$i\n"
        }
        veryLongTooltip += "\n" + "last line aaaaaa bbbbbbb cccccc dddddd eeeeee fffffff ggggggg"

        setContent {
            TestTheme {
                Scaffold { innerPadding ->
                    Column(
                        modifier = Modifier.padding(innerPadding),
                    ) {
                        TooltipButton(tooltipText = veryLongTooltip)
                    }
                }
            }
        }
    }
}


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TooltipButton(tooltipText: String) {
    val tooltipState = rememberTooltipState(isPersistent = true)

    TooltipBox(
        positionProvider = TooltipDefaults.rememberRichTooltipPositionProvider(),
        tooltip = {
            RichTooltip(
                shape = RoundedCornerShape(5.dp),
                modifier = Modifier
                    .border(4.dp, Color.Red, shape = RoundedCornerShape(5.dp))
            ) {
                Text(
                    tooltipText,
                    fontSize = 18.sp,
                    modifier = Modifier.verticalScroll(rememberScrollState())
                )
            }
        },
        state = tooltipState
    ) {
        val coroutine = rememberCoroutineScope()
        Button(
            onClick = {
                coroutine.launch { tooltipState.show() }
            }
        ) {
            Text("click to show the tooltip")
        }
    }
}

Edited:

Not sure why it happens, I ended up using a workaround to limit the max height of the Text to 90% of the screen.

@Composable
fun Modifier.maxScreenHeight(percentage: Float): Modifier = composed {
    val ctx = LocalContext.current
    val density = LocalDensity.current

    val maxHeight = density.run {
        val screenHeightPx = ctx.resources.displayMetrics.heightPixels
        screenHeightPx.toDp().value * percentage
    }

    this.then(
        Modifier.heightIn(max = maxHeight.dp)
    )
}

1 Answer 1

1

It looks like you need to set window insets to keep the Activity's contents out of the system bars when in edge-to-edge mode (which Android 15 pretty much requires).

See Behavior changes for Apps targeting Android 15 .

Here's more info and a Kotlin example from https://developer.android.com/develop/ui/views/layout/edge-to-edge#cutout-insets

ViewCompat.setOnApplyWindowInsetsListener(binding.recyclerView) { v, insets ->
  val bars = insets.getInsets(
    WindowInsetsCompat.Type.systemBars()
      or WindowInsetsCompat.Type.displayCutout()
  )
  v.updatePadding(
    left = bars.left,
    top = bars.top,
    right = bars.right,
    bottom = bars.bottom,
  )
  WindowInsetsCompat.CONSUMED
}

In practice, you'll have to decide which view(s) to set the insets on. You could apply it to the entire Activity or some part of it instead of this example's RecyclerView.

As usual, the docs are skimpy. This Medium post helps: Insets handling tips for Android 15’s edge-to-edge enforcement

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.