Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose: Disable Interaction with TextField

Is there a way to disable all interaction for Jetpack Compose's TextField?

like image 982
Archie G. Quiñones Avatar asked Dec 09 '20 13:12

Archie G. Quiñones


People also ask

How do I disable a button in compose?

You can enable or disable the option to always show the compose button, by using More... | Global Settings | Customize Appearance | check / uncheck Always show compose button.

How do I get TextField value in jetpack compose?

To read value entered in TextField in Android Compose, declare a variable, and assign this variable the value in the TextField whenever there is a change in the value. The same process holds for reading value entered in OutlineTextField composable.

What is mutableStateOf in jetpack compose?

mutableStateOf creates an observable MutableState<T> , which is an observable type integrated with the compose runtime. interface MutableState<T> : State<T> { override var value: T. } Any changes to value will schedule recomposition of any composable functions that read value .

What is LazyColumn in jetpack compose?

A LazyColumn is a vertically scrolling list that only composes and lays out the currently visible items. It's similar to a Recyclerview in the classic Android View system.

What is textfield in jetpack compose?

TextField in Jetpack Compose What's TextField? TextField is a user interface control that is used to allow the user to enter the text. This widget is used to get the data from the user as numbers or text. A simple example of TextField is Login page. We get the username and password using TextField widget. What are options available in TextField?

What are textfield and textfield in compose?

At a higher level, Compose provides Text and TextField , which are composables following Material Design guidelines. It’s recommended to use them as they have the right look and feel for users on Android, and includes other options to simplify their customization without having to write a lot of code.

How do I create a jetpack project in Android Studio?

Knowledge in Jetpack compose. Physical device or emulator to run the application. To get started, open up Android Studio and create a new project using the “Empty Compose activity” template. Give it any name you would like. You can go ahead to customize the theme to your liking.

How do I select text from a composable element?

By default, composables aren’t selectable, which means by default users can't select and copy text from your app. To enable text selection, you need to wrap your text elements with a SelectionContainer composable: You may want to disable selection on specific parts of a selectable area.


1 Answers

With 1.0.0 you can use the enabled attribute:

enabled : controls the enabled state of the TextField. When false, the text field will be neither editable nor focusable, the input of the text field will not be selectable, visually text field will appear in the disabled UI state

Something like:

var text by rememberSaveable { mutableStateOf("Text") }

TextField(
    value = text,
    onValueChange = { text = it },
    enabled = false,
    label = { Text("Label") },
    singleLine = true
)
like image 137
Gabriele Mariotti Avatar answered Nov 05 '22 11:11

Gabriele Mariotti