Compose 搜索框

@Composable
fun CustomStyledTextField(
) {
    var text by remember { mutableStateOf("搜索") }
    // Define the text style with desired font size
    val textStyle = TextStyle(
        fontSize = 8.sp, // Set the font size here
        fontWeight = FontWeight.Normal // You can adjust font weight as needed
    )

    Box(
        modifier = Modifier
            .size(374.dp.px(), 50.dp.px())
            .background(Color(0xffffff00), shape = RoundedCornerShape(15))
//            .border(0.dp, Color.Gray, shape = RoundedCornerShape(8.dp))
            .padding(1.dp).padding(start = 2.dp)
    ) {
        BasicTextField(
            textStyle = textStyle,
            value = text,
            onValueChange = {
                text = it
            },
//            modifier = Modifier.fillMaxWidth(),
            singleLine = true,
            decorationBox = { innerTextField ->
                Row(
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    // Place the text field
                    Box(modifier = Modifier.weight(1f)) {
                        innerTextField()
                    }
//                    Image(
//                        painter = painterResource(id = R.drawable.search_icon),
//                        contentDescription = "Vector Image Example",
//                        modifier = Modifier.size(70.dp.px(),42.dp.px()) // Adjust size if needed
//                    )
                    // Add an icon at the end
                    Icon(
                        imageVector = Icons.Default.Search,
                        contentDescription = "Search Icon",
                        modifier = Modifier.size(24.dp)
                    )
                }
            }
        )
    }
}


在这里插入图片描述

@Composable
fun CustomStyledTextField(
) {
    var text by remember { mutableStateOf("搜索") }
    // Define the text style with desired font size
    val textStyle = TextStyle(
        fontSize = 8.sp, // Set the font size here
        fontWeight = FontWeight.Normal // You can adjust font weight as needed
    )

    Box(
        modifier = Modifier
            .size(374.dp.px(), 50.dp.px())
            .background(Color(0x66ffffff), shape = RoundedCornerShape(15))
//            .border(1.dp, Color.Gray, shape = RoundedCornerShape(1.dp))
            .padding(1.dp)
            .padding(start = 2.dp)
    ) {
        BasicTextField(
            textStyle = textStyle,
            value = text,
            onValueChange = {
                text = it
            },
            singleLine = true,
            decorationBox = { innerTextField ->
                Row(
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    // Place the text field
                    Box(modifier = Modifier.weight(1f)) {
                        innerTextField()
                    }
                    // Add an icon at the end
                    Box(modifier = Modifier.background(Color.Blue, shape = RoundedCornerShape(15)).clickable {  }) {
                        Icon(
                            imageVector = Icons.Default.Search,
                            tint = Color.White,
                            contentDescription = "Search Icon",
                            modifier = Modifier.size(24.dp)
                        )
                    }
                }
            }
        )
    }
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值