10.1 實戰(zhàn):B站風格輸入框

Compose筆記 1
TEXT組件學習
class MainActivity : ComponentActivity() {
? ?override fun onCreate(savedInstanceState: Bundle?) {
? ? ? ?super.onCreate(savedInstanceState)
? ? ? ?setContent {
? ? ? ? ? ?SearchBar()
? ? ? ?}
? ?}
}
@Composable
fun SearchBar() {
? ?var text by remember { mutableStateOf("") }
? ?Box(
? ? ? ?modifier = Modifier
? ? ? ? ? ?.fillMaxSize()
? ? ? ? ? ?.background(Color(0xFFD3D3D3), shape = CircleShape),
? ? ? ?contentAlignment = Alignment.Center
? ?) {
? ? ? ?BasicTextField(
? ? ? ? ? ?value = text,
? ? ? ? ? ?onValueChange ={
? ? ? ? ? ? ? ?text = it
? ? ? ? ? ?},
? ? ? ? ? ?decorationBox = { innerTextField ->
? ? ? ? ? ? ? ?innerTextField()
? ? ? ? ? ?},
? ? ? ? ? ?modifier = Modifier
? ? ? ? ? ? ? ?.padding(horizontal = 10.dp)
? ? ? ? ? ? ? ?.background(Color.White, CircleShape)
? ? ? ? ? ? ? ?.height(30.dp)
? ? ? ? ? ? ? ?.fillMaxWidth()
? ? ? ?)
? ?}
}
