Skip to content

Commit 113e972

Browse files
committed
Update StateBasedText.kt
Update state based TF snippets
1 parent a9a6a55 commit 113e972

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

compose/snippets/src/main/java/com/example/compose/snippets/text/StateBasedText.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package com.example.compose.snippets.text
1818

1919
import android.text.TextUtils
20+
import androidx.compose.foundation.layout.Column
2021
import androidx.compose.foundation.layout.padding
21-
import androidx.compose.foundation.text.BasicTextField
2222
import androidx.compose.foundation.text.KeyboardOptions
2323
import androidx.compose.foundation.text.input.InputTransformation
2424
import androidx.compose.foundation.text.input.OutputTransformation
@@ -32,6 +32,7 @@ import androidx.compose.foundation.text.input.rememberTextFieldState
3232
import androidx.compose.foundation.text.input.selectAll
3333
import androidx.compose.foundation.text.input.setTextAndPlaceCursorAtEnd
3434
import androidx.compose.foundation.text.input.then
35+
import androidx.compose.material.OutlinedTextField
3536
//noinspection UsingMaterialAndMaterial3Libraries
3637
import androidx.compose.material.TextField
3738
//noinspection UsingMaterialAndMaterial3Libraries
@@ -50,23 +51,36 @@ import androidx.compose.ui.unit.dp
5051
import androidx.core.text.isDigitsOnly
5152
import androidx.lifecycle.ViewModel
5253

54+
@Preview
5355
@Composable
5456
fun StateBasedTextSnippets() {
55-
// [START android_compose_state_text_1]
56-
BasicTextField(state = rememberTextFieldState())
57+
Column() {
58+
// [START android_compose_state_text_0]
59+
TextField(
60+
state = rememberTextFieldState(initialText = "Hello"),
61+
label = { Text("Label")}
62+
)
63+
// [END android_compose_state_text_0]
5764

58-
TextField(state = rememberTextFieldState())
59-
// [END android_compose_state_text_1]
65+
// [START android_compose_state_text_1]
66+
OutlinedTextField(
67+
state = rememberTextFieldState(),
68+
label = { Text("Label") }
69+
)
70+
// [END android_compose_state_text_1]
71+
}
6072
}
6173

74+
@Preview
6275
@Composable
6376
fun StyleTextField() {
6477
// [START android_compose_state_text_2]
6578
TextField(
66-
state = rememberTextFieldState(),
79+
state = rememberTextFieldState("Hello\nWorld\nInvisible"),
6780
lineLimits = TextFieldLineLimits.MultiLine(maxHeightInLines = 2),
6881
placeholder = { Text("") },
6982
textStyle = TextStyle(color = Color.Blue, fontWeight = FontWeight.Bold),
83+
label = { Text("Enter text")},
7084
modifier = Modifier.padding(20.dp)
7185
)
7286
// [END android_compose_state_text_2]

0 commit comments

Comments
 (0)