17
17
package com.example.compose.snippets.text
18
18
19
19
import android.text.TextUtils
20
+ import androidx.compose.foundation.layout.Column
21
+ import androidx.compose.foundation.layout.Spacer
22
+ import androidx.compose.foundation.layout.height
20
23
import androidx.compose.foundation.layout.padding
21
- import androidx.compose.foundation.text.BasicTextField
22
24
import androidx.compose.foundation.text.KeyboardOptions
23
25
import androidx.compose.foundation.text.input.InputTransformation
24
26
import androidx.compose.foundation.text.input.OutputTransformation
@@ -32,6 +34,7 @@ import androidx.compose.foundation.text.input.rememberTextFieldState
32
34
import androidx.compose.foundation.text.input.selectAll
33
35
import androidx.compose.foundation.text.input.setTextAndPlaceCursorAtEnd
34
36
import androidx.compose.foundation.text.input.then
37
+ import androidx.compose.material.OutlinedTextField
35
38
// noinspection UsingMaterialAndMaterial3Libraries
36
39
import androidx.compose.material.TextField
37
40
// noinspection UsingMaterialAndMaterial3Libraries
@@ -50,23 +53,36 @@ import androidx.compose.ui.unit.dp
50
53
import androidx.core.text.isDigitsOnly
51
54
import androidx.lifecycle.ViewModel
52
55
56
+ @Preview
53
57
@Composable
54
58
fun StateBasedTextSnippets () {
55
- // [START android_compose_state_text_1]
56
- BasicTextField (state = rememberTextFieldState())
59
+ Column () {
60
+ // [START android_compose_state_text_0]
61
+ TextField (
62
+ state = rememberTextFieldState(initialText = " Hello" ),
63
+ label = { Text (" Label" ) }
64
+ )
65
+ // [END android_compose_state_text_0]
57
66
58
- TextField (state = rememberTextFieldState())
59
- // [END android_compose_state_text_1]
67
+ // [START android_compose_state_text_1]
68
+ OutlinedTextField (
69
+ state = rememberTextFieldState(),
70
+ label = { Text (" Label" ) }
71
+ )
72
+ // [END android_compose_state_text_1]
73
+ }
60
74
}
61
75
76
+ @Preview
62
77
@Composable
63
78
fun StyleTextField () {
64
79
// [START android_compose_state_text_2]
65
80
TextField (
66
- state = rememberTextFieldState(),
81
+ state = rememberTextFieldState(" Hello \n World \n Invisible " ),
67
82
lineLimits = TextFieldLineLimits .MultiLine (maxHeightInLines = 2 ),
68
83
placeholder = { Text (" " ) },
69
84
textStyle = TextStyle (color = Color .Blue , fontWeight = FontWeight .Bold ),
85
+ label = { Text (" Enter text" ) },
70
86
modifier = Modifier .padding(20 .dp)
71
87
)
72
88
// [END android_compose_state_text_2]
@@ -80,10 +96,15 @@ fun ConfigureLineLimits() {
80
96
lineLimits = TextFieldLineLimits .SingleLine
81
97
)
82
98
// [END android_compose_state_text_3]
99
+ }
83
100
101
+ @Preview
102
+ @Composable
103
+ fun Multiline () {
104
+ Spacer (modifier = Modifier .height(15 .dp))
84
105
// [START android_compose_state_text_4]
85
106
TextField (
86
- state = rememberTextFieldState(),
107
+ state = rememberTextFieldState(" Hello \n World \n Hello \n World " ),
87
108
lineLimits = TextFieldLineLimits .MultiLine (1 , 4 )
88
109
)
89
110
// [END android_compose_state_text_4]
0 commit comments