Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – How to make area behind transparent color not interactable/clickable in Jetpack Compose?

Posted on November 11, 2022 By

Solution 1 :

You can have a Box that consumes click events without click feedback:

val interactionSource = remember { MutableInteractionSource() }
Box(
    modifier = modifier
        .background(
            color = MaterialTheme.colors.surface.copy(alpha = .4f)
        )
        .clickable(
            onClick = {
                if (dismissOnTouchOutside) {
                    onDismiss()
                }
            },
            interactionSource = interactionSource,
            indication = null
        ),
    contentAlignment = Alignment.Center,
) {
    // content here
}

Problem :

Consider that this composable, which acts as a “Dialog”, is being drawn in front the root application:

screenshot showing the composables

I tried to simulate this dialog by making it fit the entire screen and making its root container have a basic background(Color.Gray.copy(alpha = 0.5f) modifier.

However, even it is in front still being possible to interact with that top buttons.

My question is if there’s a “direct” way to “disable” interactions of a particular composable tree to avoid passing parameters (such as “clickable”) to all affected composables?

I thought doing something like:

  • take a “screenshot” from the area behind the alpha color;
  • draw the screenshot as an Image;
  • then draw the in-front composable (in my example, the “dialog”).

However, I don’t know how worth this is to implement or even how to take that “screenshot”.

Also, may be an way to handle this using something relatad to remember compostion state or so on.

Comments

Comment posted by Lucas Sousa

Perfect!

Comment posted by Anders Ullnæss

If you need this often, you can make it an extension function on Modifier:

Comment posted by Lucas Sousa

Really great, @AndersUllnæss

READ  [FIXED] android - Get firebase child values
Powered by Inline Related Posts
Android Tags:android, android-jetpack-compose, jetbrains-compose, kotlin

Post navigation

Previous Post: [FIXED] Android ACTION_VIEW intent is not opening urls in non-browser apps like twitter and instagram
Next Post: [FIXED] android – Check if activity is active, and if active pass data from service to activity?

Related Posts

[FIXED] android – Can I use a FloatingActionButton “on top” of my layout? So that it is overlapping all forms? Android
[FIXED] android – Comparing Text Fields Value Android
[FIXED] android – Kotlin : Edit a pdf programmatically or an html Android
[FIXED] How to remove fingerprint authentication from Android KeyGaurd manager? Android
[FIXED] Getting data from Firebase and use data to allowed user of Android Apps Android
[FIXED] progressdialog – Android studio progress dialog not showing progress? Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is a good substitute for condensed milk?
  • ¿Como el cuerpo te avisa cuando te va a dar un infarto?
  • What is the luxury brand of Jaguar?
  • Who is Big poppa baseball player?
  • What material are foam runners?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme