TextField

img img

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@Composable
fun TextFieldSample() {
    //使用by remember才會記憶value
    var value by remember {
        mutableStateOf("")
    }
    TextField(
        value = value,
        onValueChange = {
            //把輸入的值放在value變數
            value = it
        },
        label = {//標籤
            Text("name")
        },
        placeholder = {
            Text(text = "請輸入")
        },
        leadingIcon = {//前置圖片
            Icon(imageVector = Icons.Default.AccountBox, contentDescription = null)
        },
        keyboardActions = KeyboardActions(onDone = {
            //處理按下完成
        }),
        singleLine = true,//單行
        keyboardOptions = KeyboardOptions(
            imeAction = ImeAction.Done,//回車鍵有完成的按鈕
            keyboardType = KeyboardType.Number//數字
        )
    )
}
@Preview
@Composable
fun TextFieldSamplePreview() {
    TextFieldSample()
}

results matching ""

    No results matching ""