如何在桌面中隐藏按钮

发布于 2025-01-23 01:56:13 字数 316 浏览 6 评论 0原文

我正在使用

OutlinedButton(
        onClick = {
            // Perform an operation
            // Hide the button
        }) {
        Text(text = "CLick Here")
    }

与Android相比,桌面组合没有可见性修饰符。
对于Eg vienibility = view.gone

那么如何隐藏onclick事件上的按钮?

I am developing an app with Desktop Compose Multi-Platform.
I need to hide the button when it has been clicked.
Please see below code:

OutlinedButton(
        onClick = {
            // Perform an operation
            // Hide the button
        }) {
        Text(text = "CLick Here")
    }

As compared to android, Desktop Compose does not have visibility modifiers.
for e.g. visibility = View.GONE

So how to hide the button on the onClick event ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

和我恋爱吧 2025-01-30 01:56:13

组合中的任何视图修改都是使用状态变量进行的。

如果您需要完全删除视图,则可以这样做:

var isButtonVisible by remember { mutableStateOf(true) }
if (isButtonVisible) {
    OutlinedButton(
        onClick = {
            // Perform an operation
            isButtonVisible = false
        }) {
        Text(text = "CLick Here")
    }
}

如果要在布局中保存空间,则只需使用modifier.alpha将其隐藏。例如,如果您有一个带有几个元素的行,并且您不希望它们在按钮消失后移动。

var isButtonVisible by remember { mutableStateOf(true) }
OutlinedButton(
    onClick = {
        // Perform an operation
        isButtonVisible = false
    },
    modifier = Modifier.alpha(if (isButtonVisible) 1f else 0f)
) {
    Text(text = "CLick Here")
}

我建议您在compose

Any view modifications in Compose are done using state variables.

If you need the view to be completely removed, you can do it like this:

var isButtonVisible by remember { mutableStateOf(true) }
if (isButtonVisible) {
    OutlinedButton(
        onClick = {
            // Perform an operation
            isButtonVisible = false
        }) {
        Text(text = "CLick Here")
    }
}

If you want to save space in the layout, you can simply hide it with Modifier.alpha. For example, if you have a row with a couple of elements and you don't want them to move after the button disappears.

var isButtonVisible by remember { mutableStateOf(true) }
OutlinedButton(
    onClick = {
        // Perform an operation
        isButtonVisible = false
    },
    modifier = Modifier.alpha(if (isButtonVisible) 1f else 0f)
) {
    Text(text = "CLick Here")
}

I suggest you check out with state in Compose documentation, including this youtube video which explains the basic principles.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文