Skip to main content
ubuntuask.com

Back to all posts

How to Set Button Visibility In Kotlin?

Published on
4 min read
How to Set Button Visibility In Kotlin? image

Best Kotlin Development Tools to Buy in July 2026

1 Thriving in Android Development Using Kotlin: A project-based guide to using the latest Android features for developing production-grade apps

Thriving in Android Development Using Kotlin: A project-based guide to using the latest Android features for developing production-grade apps

BUY & SAVE
$38.49 $44.99
Save 14%
Thriving in Android Development Using Kotlin: A project-based guide to using the latest Android features for developing production-grade apps
2 Kotlin Programming: The Big Nerd Ranch Guide

Kotlin Programming: The Big Nerd Ranch Guide

BUY & SAVE
$53.07
Kotlin Programming: The Big Nerd Ranch Guide
3 Learn Android Studio 3 with Kotlin: Efficient Android App Development

Learn Android Studio 3 with Kotlin: Efficient Android App Development

BUY & SAVE
$45.29 $59.99
Save 25%
Learn Android Studio 3 with Kotlin: Efficient Android App Development
4 Head First Android Development: A Learner's Guide to Building Android Apps with Kotlin

Head First Android Development: A Learner's Guide to Building Android Apps with Kotlin

BUY & SAVE
$59.30 $89.99
Save 34%
Head First Android Development: A Learner's Guide to Building Android Apps with Kotlin
5 Learn Kotlin for Android Development: The Next Generation Language for Modern Android Apps Programming

Learn Kotlin for Android Development: The Next Generation Language for Modern Android Apps Programming

BUY & SAVE
$35.81
Learn Kotlin for Android Development: The Next Generation Language for Modern Android Apps Programming
6 Kotlin Essentials (Kotlin for Developers Book 1)

Kotlin Essentials (Kotlin for Developers Book 1)

BUY & SAVE
$24.99
Kotlin Essentials (Kotlin for Developers Book 1)
7 Android UI Development with Jetpack Compose: Bring declarative and native UI to life quickly and easily on Android using Jetpack Compose and Kotlin

Android UI Development with Jetpack Compose: Bring declarative and native UI to life quickly and easily on Android using Jetpack Compose and Kotlin

BUY & SAVE
$36.99
Android UI Development with Jetpack Compose: Bring declarative and native UI to life quickly and easily on Android using Jetpack Compose and Kotlin
8 Beginning Kotlin: Build Applications with Better Code, Productivity, and Performance

Beginning Kotlin: Build Applications with Better Code, Productivity, and Performance

BUY & SAVE
$24.53 $37.99
Save 35%
Beginning Kotlin: Build Applications with Better Code, Productivity, and Performance
9 Advanced Kotlin (Kotlin for Developers Book 4)

Advanced Kotlin (Kotlin for Developers Book 4)

BUY & SAVE
$29.99
Advanced Kotlin (Kotlin for Developers Book 4)
10 Modern Android 13 Development Cookbook: Over 70 recipes to solve Android development issues and create better apps with Kotlin and Jetpack Compose

Modern Android 13 Development Cookbook: Over 70 recipes to solve Android development issues and create better apps with Kotlin and Jetpack Compose

BUY & SAVE
$36.99 $49.99
Save 26%
Modern Android 13 Development Cookbook: Over 70 recipes to solve Android development issues and create better apps with Kotlin and Jetpack Compose
+
ONE MORE?

In Kotlin, you can set the visibility of a button, or any other View, by using the visibility property. The visibility property accepts three constants: View.VISIBLE, View.INVISIBLE, and View.GONE.

  1. View.VISIBLE makes the button visible and takes up space in the layout.
  2. View.INVISIBLE hides the button, but it still occupies space in the layout.
  3. View.GONE hides the button and also removes it from the layout, so it does not take up any space.

To set the visibility of a button, you can simply call the visibility property on the button instance and assign the desired constant value. For example:

// Assuming you have a button with the id "myButton" in your layout XML val button = findViewById