Ask Your Question
2

How can a debug banner similar to the one on Flutter be added on Jetpack Compose?

asked 2022-02-04 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-02-13 14:00:00 +0000

lakamha gravatar image

To add a debug banner similar to the one on Flutter in Jetpack Compose, you can create a customized Composable function that will wrap the main content of your application with a banner that displays the current build type or any other custom information you want to show.

Here's an example implementation that you can use as a starting point:

@Composable
fun DebugBanner(
    info: String = "",
    color: Color = Color.Red,
    modifier: Modifier = Modifier
) {
    if (BuildConfig.DEBUG) {
        Box(
            modifier = modifier.fillMaxWidth()
                .padding(top = 32.dp)
                .background(color)
        ) {
            Text(
                text = info,
                color = Color.White,
                fontSize = 12.sp,
                modifier = Modifier.padding(8.dp)
            )
        }
    }
}

In this implementation, the DebugBanner function takes in a String parameter for the information text and a Color parameter for the banner background color. You can customize these parameters to fit your needs.

To use this DebugBanner function, simply wrap your main content with it like this:

ContentScreen() {
    DebugBanner(info = "Debug Mode")
    // Main content goes here
}

This will add the debug banner above your main content only in debug mode.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-02-04 11:00:00 +0000

Seen: 11 times

Last updated: Feb 13 '22