Jetpack撰写用户界面:如何创建SearchView?

时间:2019-11-13 15:08:24

标签: android android-jetpack-compose

我想使用jetpack compose创建SearchView,但是找不到任何可以帮助我的示例。预先感谢。

enter image description here

2 个答案:

答案 0 :(得分:0)

如果要创建类似的UI,只需使用FlexRow创建组件。

FlexRow(crossAxisAlignment = CrossAxisAlignment.Start) {
    inflexible {
        drawImageResource(R.drawable.image_search)

    }
    expanded(1.0f) {
        SingleLineEditText(
            state,
            keyboardType = KeyboardType.Text,
            imeAction = ImeAction.Search,
            editorStyle = EditorStyle(textStyle = TextStyle(fontSize = 16.sp)),
            onImeActionPerformed = {
                onSearch(state.value.text)
            }
        )
    }
}

答案 1 :(得分:0)

TextField(
   startingIcon = Icon(bitmap = searchIcon),
   placeholder = { Text(...) }
)