国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

《Jetpack Compose從入門到實戰(zhàn)》 第二章 了解常用UI組件

這篇具有很好參考價值的文章主要介紹了《Jetpack Compose從入門到實戰(zhàn)》 第二章 了解常用UI組件。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

《Jetpack Compose從入門到實戰(zhàn)》 第二章 了解常用UI組件,安卓,安卓
書附代碼
Google的圖標(biāo)庫

常用的基礎(chǔ)組件

文字組件


@Composable
fun TestText() {
    Column(modifier = Modifier.verticalScroll(state = rememberScrollState())) {
        Text(text = "hello world")
        Text(text = "hello world")
        Text(text = "hello world")
        Text(text = stringResource(id = R.string.hello_world))
        Text(
            text = stringResource(id = R.string.hello_world),
            style = TextStyle(
                fontSize = 25.sp,//字體大小
                fontWeight = FontWeight.Bold,//字體粗細
                fontStyle = FontStyle.Italic,//斜體,
                background = Color.Cyan,
                lineHeight = 35.sp,//行高
            ),
        )
        Text(
            text = stringResource(id = R.string.hello_world),
            style = TextStyle(color = Color.Gray, letterSpacing = 4.sp)
        )
        Text(
            text = stringResource(id = R.string.hello_world),
            style = TextStyle(textDecoration = TextDecoration.LineThrough)
        )

        Text(
            text = stringResource(id = R.string.hello_world),
            style = MaterialTheme.typography.h6.copy(fontStyle = FontStyle.Italic)
        )

        Text(
            text = "Hello Compose, Compose是下一代Android UI工具包, 開發(fā)起來和以往XML寫布局有著非常大的不同",
            style = MaterialTheme.typography.body1
        )
        Text(
            text = "Hello Compose, Compose是下一代Android UI工具包, 開發(fā)起來和以往XML寫布局有著非常大的不同",
            style = MaterialTheme.typography.body1,
            maxLines = 1
        )
        Text(
            text = "Hello Compose, Compose是下一代Android UI工具包, 開發(fā)起來和以往XML寫布局有著非常大的不同",
            style = MaterialTheme.typography.body1,
            maxLines = 1,
            overflow = TextOverflow.Ellipsis,
        )

        Text(text = stringResource(id = R.string.hello_world), fontFamily = FontFamily.Cursive)
        Text(text = stringResource(id = R.string.hello_world), fontFamily = FontFamily.Monospace)
        Text(
            text = "你好,我的世界", fontFamily = FontFamily(Font(R.font.test_font))
        )

        Text(text = buildAnnotatedString {
            appendLine("-------------------------------")
            withStyle(style = SpanStyle(fontSize = 24.sp)) {
                append("你現(xiàn)在學(xué)的章節(jié)是")
            }
            withStyle(style = SpanStyle(fontWeight = FontWeight.W900, fontSize = 24.sp)) {
                append("Text")
            }
            appendLine()
            withStyle(style = ParagraphStyle(lineHeight = 25.sp)) {
                append("在剛剛講過的內(nèi)容中, 我們學(xué)會了如何應(yīng)用文字樣式, 以及如何限制文本的行數(shù)和處理溢出的視覺效果")
            }
            appendLine()
            append("現(xiàn)在,我們正在學(xué)習(xí)")
            withStyle(
                style = SpanStyle(
                    fontWeight = FontWeight.W900,
                    textDecoration = TextDecoration.Underline,
                    color = Color(0xFF59A869)
                )
            ) {
                append("AnnotatedString")
            }

        })
        val annotatedString = buildAnnotatedString {
            withStyle(style = ParagraphStyle()) {
                append("點擊下面的鏈接查看更多")
                pushStringAnnotation(
                    tag = "URL", annotation = "https://jetpackcompose.cn/docs/elements/text"
                )
                withStyle(
                    style = SpanStyle(
                        fontWeight = FontWeight.W900,
                        textDecoration = TextDecoration.Underline,
                        color = Color(0xFF59A869)
                    )
                ) {
                    append("參考鏈接")
                }
                pop()//結(jié)束之前添加的樣式
                appendLine("-------------------------------")
            }
        }

        val currentContext = LocalContext.current
        ClickableText(text = annotatedString, onClick = { offset ->
            annotatedString.getStringAnnotations(tag = "URL", start = offset, end = offset)
                .firstOrNull()?.let { annotation ->
                    val uri: Uri = Uri.parse(annotation.item)
                    val intent = Intent(Intent.ACTION_VIEW, uri)
                    startActivity(currentContext, intent, null)
                }
        })

        SelectionContainer {
            Text(text = "可以被選中復(fù)制的文字")
        }
        TestTextField()
    }
}

@Composable
fun TestTextField() {
    var textFields by remember { mutableStateOf("") }
    TextField(value = textFields,
        onValueChange = { textFields = it },
        label = { Text(text = "user name") })

    var userName by remember {
        mutableStateOf("")
    }

    var password by remember {
        mutableStateOf("")
    }

    TextField(value = userName,
        onValueChange = { userName = it },
        label = { Text(text = "用戶名") },
        leadingIcon = {
            Icon(
                imageVector = Icons.Filled.AccountBox, contentDescription = "username"
            )
        })

    TextField(value = password,
        onValueChange = { password = it },
        label = { Text(text = "密碼") },
        trailingIcon = {
            IconButton(onClick = {}) {
                Icon(
                    painter = painterResource(id = R.drawable.visibility),
                    contentDescription = "password"
                )
            }
        })
    var outlinedTextFields by remember { mutableStateOf("Hello World") }
    OutlinedTextField(value = outlinedTextFields, onValueChange = { outlinedTextFields = it })

    //不是basicTextField,屬性被material theme所限制,例如修改高度,輸入?yún)^(qū)域會被截斷,影響顯示效果
    TextField(value = userName,
        onValueChange = { userName = it },
        label = { Text(text = "用戶名") },
        leadingIcon = {
            Icon(
                imageVector = Icons.Filled.AccountCircle, contentDescription = null
            )
        },
        modifier = Modifier.height(30.dp)
    )


    var basicTextFields by remember { mutableStateOf("") }

    BasicTextField(
        value = basicTextFields,
        onValueChange = { basicTextFields = it },
        decorationBox = { innerTextField ->
            Column {
                innerTextField.invoke()//innerTextField代表輸入框開始輸入的位置,需要在合適的地方調(diào)用
                Divider(
                    thickness = 1.dp, modifier = Modifier
                        .fillMaxWidth()
                        .background(Color.Black)
                )
            }
        },
        modifier = Modifier
            .height(40.dp)
            .background(Color.Cyan),
    )
    Spacer(modifier = Modifier.height(15.dp))
    SearchBar()
    Spacer(modifier = Modifier.height(15.dp))

}

@Composable
fun SearchBar() {
    var searchText by remember { mutableStateOf("") }
    Box(
        modifier = Modifier
            .fillMaxWidth()
            .height(50.dp)
            .background(Color(0xFFD3D3D3)),
        contentAlignment = Alignment.Center
    ) {
        BasicTextField(
            value = searchText,
            onValueChange = { searchText = it },
            decorationBox = { innerTextField ->
                Row(
                    verticalAlignment = Alignment.CenterVertically,
                    modifier = Modifier.padding(vertical = 2.dp, horizontal = 8.dp)
                ) {
                    Icon(imageVector = Icons.Filled.Search, contentDescription = "")
                    Box(
                        modifier = Modifier
                            .padding(horizontal = 10.dp)
                            .weight(1f),
                        contentAlignment = Alignment.CenterStart
                    ) {
                        if (searchText.isEmpty()) {
                            Text(text = "搜索", style = TextStyle(color = Color(0, 0, 0, 128)))
                        }
                        innerTextField()
                    }
                    if (searchText.isNotEmpty()) {
                        IconButton(
                            onClick = { searchText = "" }, modifier = Modifier.size(16.dp)
                        ) {
                            Icon(imageVector = Icons.Filled.Clear, contentDescription = "")
                        }
                    }
                }
            },
            modifier = Modifier
                .padding(horizontal = 10.dp)
                .height(30.dp)
                .fillMaxWidth()
                .background(Color.White, CircleShape),
        )
    }
}

《Jetpack Compose從入門到實戰(zhàn)》 第二章 了解常用UI組件,安卓,安卓

圖片組件

@Composable
fun TestImage() {
    Column {

        //Material Icon默認的tint顏色會是黑色, 所以彩色的icon,也會變成黑色
        Icon(
            imageVector = ImageVector.vectorResource(id = R.drawable.collect),//xml svg矢量圖
            contentDescription = "矢量圖資源"
        )
        //將tint設(shè)置為Color.Unspecified, 即可顯示出多色圖標(biāo)
        Icon(
            imageVector = ImageVector.vectorResource(id = R.drawable.collect),//xml svg矢量圖
            contentDescription = "矢量圖資源", tint = Color.Unspecified
        )

        Icon(
            bitmap = ImageBitmap.imageResource(id = R.drawable.gallery), contentDescription = "圖片資源"//加載jpg或png
        )

        Icon(painter = painterResource(id = R.drawable.visibility), contentDescription = "任意類型的資源")//任意類型的資源文件

        Image(
            imageVector = ImageVector.vectorResource(id = R.drawable.collect),//xml svg矢量圖
            contentDescription = "矢量圖資源"
        )

        Image(
            bitmap = ImageBitmap.imageResource(id = R.drawable.gallery), contentDescription = "圖片資源"//加載jpg或png
        )

        Image(painter = painterResource(id = R.drawable.visibility), contentDescription = "任意類型的資源")//任意類型的資源文件

    }
}

按鈕組件

@Composable
fun TestButton() {
    Column {
        Button(onClick = {}, contentPadding = PaddingValues(2.dp)) {
            Text(text = "確認")
        }

        Button(
            onClick = {},
            contentPadding = PaddingValues(5.dp),
            colors = ButtonDefaults.buttonColors(
                backgroundColor = Color.Cyan, contentColor = Color.Gray
            )
        ) {
            Icon(
                imageVector = Icons.Filled.Done,
                contentDescription = "",
                modifier = Modifier.size(ButtonDefaults.IconSize)
            )
            Spacer(modifier = Modifier.width(ButtonDefaults.IconSpacing))
            Text(text = "確認")
        }

        val interactionSource = remember {
            MutableInteractionSource()
        }
        val isPressedAsState = interactionSource.collectIsPressedAsState()
        val borderColor = if (isPressedAsState.value) Color.Green else Color.Cyan

        Button(
            onClick = {},
            contentPadding = PaddingValues(horizontal = 12.dp),
            border = BorderStroke(2.dp, borderColor),
            interactionSource = interactionSource
        ) {
            Text(text = "long press")
        }

        IconButton(onClick = {}) {
            Icon(
                painter = painterResource(id = R.drawable.collect_24_x_24),
                contentDescription = "",
                tint = Color.Unspecified
            )
        }

        FloatingActionButton(onClick = {}) {
            Icon(
                Icons.Filled.KeyboardArrowUp, contentDescription = ""
            )
        }

        ExtendedFloatingActionButton(icon = {
            Icon(
                Icons.Filled.Favorite, contentDescription = "", tint = Color.Unspecified
            )
        }, text = { Text(text = "add to my favorite") }, onClick = {})

    }
}

選擇器組件

@Composable
fun TestSelector() {
    Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
        val checkedState = remember {
            mutableStateOf(true)
        }
        Checkbox(
            checked = checkedState.value,
            onCheckedChange = { checkedState.value = it },
            colors = CheckboxDefaults.colors(checkedColor = Color(0xFF0079D3))
        )

        val (state, onStateChange) = remember {
            mutableStateOf(true)
        }
        val (state2, onStateChange2) = remember {
            mutableStateOf(true)
        }
        val parentState = remember(state, state2) {
            if (state && state2) ToggleableState.On
            else if (!state && !state2) ToggleableState.Off
            else ToggleableState.Indeterminate
        }
        val onParentClick = {
            val s = parentState != ToggleableState.On
            onStateChange(s)
            onStateChange2(s)
        }
        TriStateCheckbox(
            state = parentState,
            onClick = onParentClick,
            colors = CheckboxDefaults.colors(checkedColor = MaterialTheme.colors.primary)
        )
        Row(modifier = Modifier.padding(10.dp, 0.dp, 0.dp, 10.dp)) {
            Checkbox(checked = state, onCheckedChange = onStateChange)
            Checkbox(checked = state2, onCheckedChange = onStateChange2)

        }

        val switchCheckedState = remember {
            mutableStateOf(true)
        }
        Switch(
            checked = switchCheckedState.value,
            onCheckedChange = { switchCheckedState.value = it },
            colors = SwitchDefaults.colors(
                checkedThumbColor = Color.Cyan, checkedTrackColor = Color.Gray
            )
        )

        var sliderPosition by remember {
            mutableStateOf(0f)
        }
        Text(
            text = "%.1f".format(sliderPosition * 100) + "%",
            modifier = Modifier.align(alignment = CenterHorizontally)
        )
        Slider(value = sliderPosition, onValueChange = { sliderPosition = it })

    }

}

對話框組件

@Composable
fun TestDialog() {
    Column {
        val openDialog = remember {
            mutableStateOf(false)
        }

        Button(onClick = {
            openDialog.value = !openDialog.value
        }) {
            Text(
                text = if (openDialog.value) "CloseDialog" else {
                    "OpenDialog"
                }
            )
        }

        if (openDialog.value) {
            Dialog(
                onDismissRequest = { openDialog.value = false }, properties = DialogProperties(
                    dismissOnBackPress = true, dismissOnClickOutside = true
                )
            ) {
                Box(
                    modifier = Modifier
                        .size(300.dp, 400.dp)
                        .background(Color.White)
                ) {
                    Button(onClick = {
                        openDialog.value = false
                    }, modifier = Modifier.align(Alignment.Center)) {
                        Text(text = "Close")
                    }
                }
            }
        }


        val alertDialog = remember {
            mutableStateOf(false)
        }

        Button(onClick = {
            alertDialog.value = !alertDialog.value
        }) {
            Text(
                text = if (alertDialog.value) "CloseAlertDialog" else {
                    "OpenAlertDialog"
                }
            )
        }

        if (alertDialog.value) {
            AlertDialog(onDismissRequest = { alertDialog.value = false },
                title = { Text(text = "開啟位置服務(wù)") },
                text = {
                    Text(text = "提供精確的位置使用,請務(wù)必打開")
                },
                confirmButton = {
                    Button(onClick = { alertDialog.value = false }) {
                        Text(text = "同意")
                    }
                },
                dismissButton = {
                    TextButton(onClick = { alertDialog.value = false }) {
                        Text(text = "取消")
                    }
                })
        }
    }
}

進度條組件

@Preview
@Composable
fun TestProgress() {
    var progress by remember {
        mutableStateOf(0.1f)
    }

    val animatedProgress by animateFloatAsState(targetValue = progress, animationSpec = ProgressIndicatorDefaults.ProgressAnimationSpec, label = "progressAnim")
    Column(
        modifier = Modifier
            .padding(10.dp)
            .border(2.dp, color = MaterialTheme.colors.primary),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center
    ) {
        CircularProgressIndicator(
            progress = animatedProgress,
            backgroundColor = MaterialTheme.colors.primary.copy(alpha = IndicatorBackgroundOpacity),
        )
        Spacer(modifier = Modifier.height(30.dp))

        LinearProgressIndicator(progress = animatedProgress, strokeCap = StrokeCap.Round)
        Spacer(modifier = Modifier.height(30.dp))
        Row {

            OutlinedButton(onClick = {
                if (progress >= 1.0f) {
                    return@OutlinedButton
                }
                progress += 0.1f
            }) {
                Text(text = "增加進度")
            }
            Spacer(modifier = Modifier.width(30.dp))
            OutlinedButton(onClick = {
                if (progress == 0f) {
                    return@OutlinedButton
                }
                progress -= 0.1f
            }) {
                Text(text = "減少進度")
            }
        }
    }
}

常用的布局組件

ConstraintLayout約束布局需要依賴:implementation “androidx.constraintlayout:constraintlayout-compose: $constraintlayout _version”

布局

@Preview
@Composable
fun TestLayout() {

    Column(
        modifier = Modifier
            .border(2.dp, color = MaterialTheme.colors.primary)
            .verticalScroll(
                rememberScrollState()
            )
    ) {
        Surface(
            shape = RoundedCornerShape(8.dp),
            modifier = Modifier
                .padding(horizontal = 12.dp, vertical = 10.dp)
                .fillMaxWidth(),
            elevation = 10.dp
        ) {
            Column(modifier = Modifier.padding(12.dp)) {
                Text(text = "Jetpack Compose是什么", style = MaterialTheme.typography.h6)
                Spacer(modifier = Modifier.padding(vertical = 5.dp))
                Text(
                    text = "Jetpack Compose是用于構(gòu)建原生Android UI的現(xiàn)代工具包。它采用聲明式UI的設(shè)計,擁有更簡單的自定義和實時的交互預(yù)覽功能,由Android官方團隊全新打造的UI框架。Jetpack Compose可簡化并加快Android上的界面開發(fā),使用更少的代碼、強大的工具和直觀的Kotlin API,快速打造生動而精彩的應(yīng)用。"
                )
                Row(
                    modifier = Modifier.fillMaxWidth(),
                    horizontalArrangement = Arrangement.SpaceBetween
                ) {
                    IconButton(onClick = { /*TODO*/ }) {
                        Icon(Icons.Filled.Favorite, null)
                    }
                    IconButton(onClick = { /*TODO*/ }) {
                        Icon(Icons.Filled.Add, null)
                    }
                    IconButton(onClick = { /*TODO*/ }) {
                        Icon(Icons.Filled.Star, null)
                    }
                }

            }
        }

        Spacer(modifier = Modifier.height(40.dp))
        Text(text = "約束布局")
        Spacer(modifier = Modifier.height(40.dp))

        ConstraintLayout(
            modifier = Modifier
                .width(300.dp)
                .height(100.dp)
                .padding(10.dp)
        ) {
            val (portraitImageRef, usernameTextRef, desTextRef) = remember {
                createRefs()//createRefs最多創(chuàng)建16個引用
            }
            Image(painter = painterResource(id = R.drawable.img),
                contentDescription = "",
                modifier = Modifier.constrainAs(portraitImageRef) {
                    top.linkTo(parent.top)
                    start.linkTo(parent.start)
                    bottom.linkTo(parent.bottom)
                })
            Text(text = "舞蹈系學(xué)姐",
                style = MaterialTheme.typography.h6,
                modifier = Modifier.constrainAs(usernameTextRef) {
                    top.linkTo(portraitImageRef.top)
                    start.linkTo(portraitImageRef.end, 10.dp)
                })
            Text(text = "一本非常好看的漫畫",
                style = MaterialTheme.typography.body1,
                modifier = Modifier.constrainAs(desTextRef) {
                    top.linkTo(usernameTextRef.bottom, 10.dp)
                    start.linkTo(usernameTextRef.start)
                })
        }

        Spacer(modifier = Modifier.height(40.dp))

        ConstraintLayout(
            modifier = Modifier
                .width(300.dp)
                .height(100.dp)
                .padding(10.dp)
        ) {
            val (usernameTextRef, passwordTextRef, usernameInputRef, passwordInputRef, dividerRef) = remember {
                createRefs()//createRefs最多創(chuàng)建16個引用
            }
            val barrier = createEndBarrier(usernameTextRef, passwordTextRef)

            Text(text = "用戶名", modifier = Modifier.constrainAs(usernameTextRef) {
                top.linkTo(parent.top)
                start.linkTo(parent.start)
            })

            Divider(
                Modifier
                    .fillMaxWidth()
                    .constrainAs(dividerRef) {
                        top.linkTo(usernameTextRef.bottom)
                        bottom.linkTo(passwordTextRef.top)

                    })

            Text(text = "密碼", modifier = Modifier.constrainAs(passwordTextRef) {
                top.linkTo(usernameTextRef.bottom, 19.dp)
                start.linkTo(parent.start)
            })
            OutlinedTextField(value = "456546461",
                onValueChange = {},
                modifier = Modifier.constrainAs(usernameInputRef) {
                    start.linkTo(barrier, 10.dp)
                    top.linkTo(usernameTextRef.top)
                    bottom.linkTo(usernameTextRef.bottom)
                    height = Dimension.fillToConstraints
                })


            OutlinedTextField(value = "4645136131",
                onValueChange = {},
                modifier = Modifier.constrainAs(passwordInputRef) {
                    start.linkTo(barrier, 10.dp)
                    top.linkTo(passwordTextRef.top)
                    bottom.linkTo(passwordTextRef.bottom)
                    height = Dimension.fillToConstraints
                })

        }

        Spacer(modifier = Modifier.height(20.dp))

        ConstraintLayout(
            modifier = Modifier
                .fillMaxWidth()
                .height(200.dp)
                .padding(10.dp)
                .background(Color.Gray)
        ) {
            val (backgroundRef, avatarRef, textRef) = remember {
                createRefs()
            }

            val guideLine = createGuidelineFromTop(0.4f)
            Box(modifier = Modifier
                .constrainAs(backgroundRef) {
                    top.linkTo(parent.top)
                    bottom.linkTo(guideLine)
                    width = Dimension.matchParent
                    height = Dimension.fillToConstraints
                }
                .background(Color(0xFF1E9FFF)))

            Image(painter = painterResource(id = R.drawable.avatar),
                contentDescription = "",
                modifier = Modifier.constrainAs(avatarRef) {
                    top.linkTo(guideLine)
                    bottom.linkTo(guideLine)
                    start.linkTo(parent.start)
                    end.linkTo(parent.end)
                })
            Text(text = "排雷數(shù)碼港", color = Color.White, modifier = Modifier.constrainAs(textRef) {
                top.linkTo(avatarRef.bottom, 10.dp)
                start.linkTo(parent.start)
                end.linkTo(parent.end)
            })

        }

        Spacer(modifier = Modifier.height(20.dp))
        ConstraintLayout(
            modifier = Modifier
                .fillMaxWidth()
                .height(200.dp)
                .padding(10.dp)
                .background(Color.Gray)
        ) {
            val (text1Ref, text2Ref, text3Ref, text4Ref) = remember {
                createRefs()
            }
            /*createVerticalChain(
                text1Ref, text2Ref, text3Ref, text4Ref, chainStyle = ChainStyle.Spread
            )*/
            /*createVerticalChain(
                text1Ref, text2Ref, text3Ref, text4Ref, chainStyle = ChainStyle.Packed
            )*/
            createVerticalChain(
                text1Ref, text2Ref, text3Ref, text4Ref, chainStyle = ChainStyle.SpreadInside
            )
            Text(text = "text1", modifier = Modifier.constrainAs(text1Ref) {
                start.linkTo(parent.start)
                end.linkTo(parent.end)
            })

            Text(text = "text2", modifier = Modifier.constrainAs(text2Ref) {
                start.linkTo(parent.start)
                end.linkTo(parent.end)
            })
            Text(text = "text3", modifier = Modifier.constrainAs(text3Ref) {
                start.linkTo(parent.start)
                end.linkTo(parent.end)
            })
            Text(text = "text4", modifier = Modifier.constrainAs(text4Ref) {
                start.linkTo(parent.start)
                end.linkTo(parent.end)
            })
        }

Scaffold腳手架

data class Item(val name: String, val icon: Int)

@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
@Composable
fun TestScaffold() {

    val selectedItem by remember {
        mutableStateOf(0)
    }
    val items = listOf<Item>(
        Item("主頁", R.drawable.home),
        Item("列表", R.drawable.list),
        Item("設(shè)置", R.drawable.setting)
    )

    val scaffoldState = rememberScaffoldState()
    val scope = rememberCoroutineScope()

    Scaffold(topBar = {
        TopAppBar(title = { Text(text = "主頁") }, navigationIcon = {
            IconButton(
                onClick = {
                    scope.launch {
                        scaffoldState.drawerState.open()
                    }
                },
            ) {
                Icon(Icons.Filled.Menu, contentDescription = "")
            }
        })
    }, bottomBar = {
        BottomNavigation {
            items.forEachIndexed { index, item ->
                BottomNavigationItem(selected = selectedItem == index, onClick = { }, icon = {
                    Icon(
                        painter = painterResource(id = item.icon), contentDescription = item.name
                    )
                }, alwaysShowLabel = false, label = { Text(text = item.name) })
            }
        }
    }, drawerContent = { Text(text = "側(cè)邊欄") }, scaffoldState = scaffoldState) {
        Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
            Text(text = "主頁界面")
        }

    }
    BackHandler(enabled = scaffoldState.drawerState.isOpen) {
        scope.launch {
            scaffoldState.drawerState.close()
        }
    }
}

列表

@Preview
@Composable
fun TestList() {
    LazyColumn(
        modifier = Modifier
            .fillMaxSize()
            .background(Color.Gray),
        contentPadding = PaddingValues(35.dp),
        verticalArrangement = Arrangement.spacedBy(10.dp)
    ) {
        items((1..50).toList()) { index ->
            ContentCard(index = index)
        }
    }
}

@Composable
fun ContentCard(index: Int) {
    Card(elevation = 8.dp, modifier = Modifier.fillMaxWidth()) {
        Box(
            modifier = Modifier
                .fillMaxSize()
                .padding(15.dp), contentAlignment = Alignment.Center
        ) {
            Text(text = "第${index}卡片", style = MaterialTheme.typography.h5)
        }
    }
}

《Jetpack Compose從入門到實戰(zhàn)》第一章 全新的 Android UI 框架

《Jetpack Compose從入門到實戰(zhàn)》 第二章 了解常用UI組件

《Jetpack Compose從入門到實戰(zhàn)》第三章 定制 UI 視圖

《Jetpack Compose從入門到實戰(zhàn)》第八章 Compose頁面 導(dǎo)航

《Jetpack Compose從入門到實戰(zhàn)》第九章 Accompanist 與第三方組件庫文章來源地址http://www.zghlxwxcb.cn/news/detail-729740.html

到了這里,關(guān)于《Jetpack Compose從入門到實戰(zhàn)》 第二章 了解常用UI組件的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 【Matlab入門】 第二章 向量和矩陣

    警告!警告!你現(xiàn)在所查看的這一章,是matlab最核心、最重要的功能區(qū)塊。務(wù)必將向量組、數(shù)組(我學(xué)了C,還是這樣叫比較順口)、矩陣及其運算學(xué)明白。在學(xué)習(xí)本章之前,請觀看者有線性代數(shù)入門知識,至少要學(xué)到特征值部分,不然理解會十分困難。倘若你準(zhǔn)備好的話,進入

    2024年02月21日
    瀏覽(26)
  • ArduinoUNO實戰(zhàn)-第二十二章-紅外遙控實驗

    ArduinoUNO實戰(zhàn)-第二十二章-紅外遙控實驗

    Arduino基礎(chǔ)入門篇25—紅外遙控 Arduino與紅外遙控握手 在日常生活中我們會接觸到各式各樣的遙控器,電視機、空調(diào)、機頂盒等都有專用的遙控器,很多智能手機也在軟硬件上對紅外遙控做了支持,可以集中遙控絕大部分家用電器。 當(dāng)按下遙控器上某個按鍵,串口輸出該按鍵的

    2024年02月16日
    瀏覽(17)
  • WebRTC實戰(zhàn)-第二章-使用WebRTC實現(xiàn)音視頻通話

    WebRTC實戰(zhàn)-第二章-使用WebRTC實現(xiàn)音視頻通話

    、 什么是WebRTC|WebRTC入門到精通必看|快速學(xué)會音視頻通話原理|WebRTC超全資料分享FFmpeg/rtmp/hls/rtsp/SRS WebRTC **WebRTC詳細指南** http://www.vue5.com/webrtc/webrtc.html WEBRTC三種類型(Mesh、MCU 和 SFU)的多方通信架構(gòu) WebRTC API包括媒體捕獲,音頻和視頻編碼和解碼,傳輸層和會話管理 。 假設(shè)

    2023年04月12日
    瀏覽(20)
  • 微信小程序開發(fā)實戰(zhàn)課后習(xí)題解答————第二章(作業(yè)版)

    一、填空題 1.微信小程序通過 ? bindtap/catchtap? ? 方式實現(xiàn)單擊事件。 2.微信小程序的flex布局中, flex-direction: row ? 屬性來實現(xiàn)子元素的橫向排列 3.微信小程序中按鈕通過? ? button ? 組件來實現(xiàn) 4.微信小程序通過? display: flex 來實現(xiàn)felx布局 5.微信小程序中執(zhí)行頁面數(shù)據(jù)加載完

    2024年02月15日
    瀏覽(28)
  • 【UnityShader入門精要學(xué)習(xí)筆記】第二章(3)章節(jié)答疑

    【UnityShader入門精要學(xué)習(xí)筆記】第二章(3)章節(jié)答疑

    本系列為作者學(xué)習(xí)UnityShader入門精要而作的筆記,內(nèi)容將包括: 書本中句子照抄 + 個人批注 項目源碼 一堆新手會犯的錯誤 潛在的太監(jiān)斷更,有始無終 總之適用于同樣開始學(xué)習(xí)Shader的同學(xué)們進行有取舍的參考。 (PS:章節(jié)答疑不是我答,是原作者對一些比較容易產(chǎn)生困惑的地

    2024年02月03日
    瀏覽(29)
  • javacv從入門到精通——第二章:安裝與配置

    當(dāng)我們以Maven項目為基礎(chǔ)使用JavaCV時,需要在pom.xml文件中添加依賴項??梢栽?https://search.maven.org/ 搜索javacv,并添加以下依賴項: 下載并導(dǎo)入依賴后,即可在項目中使用JavaCV。同時,也需要確保系統(tǒng)中已經(jīng)安裝了相應(yīng)的OpenCV和FFmpeg庫,并將它們配置到環(huán)境變量中,以供JavaC

    2024年02月16日
    瀏覽(45)
  • 【Java入門合集】第二章Java語言基礎(chǔ)(三)

    【Java入門合集】第二章Java語言基礎(chǔ)(三)

    博主:命運之光 專欄:Java零基礎(chǔ)入門 學(xué)習(xí)目標(biāo) 掌握變量、常量、表達式的概念,數(shù)據(jù)類型及變量的定義方法; 掌握常用運算符的使用; 掌握程序的順序結(jié)構(gòu)、選擇結(jié)構(gòu)和循環(huán)結(jié)構(gòu)的使用; 掌握數(shù)組的定義及使用方法; 掌握基本的輸入輸出方法; Java中的語句有很多種形式

    2024年02月03日
    瀏覽(91)
  • 【Java入門合集】第二章Java語言基礎(chǔ)(一)

    【Java入門合集】第二章Java語言基礎(chǔ)(一)

    博主:命運之光 專欄:Java零基礎(chǔ)入門 學(xué)習(xí)目標(biāo) 掌握變量、常量、表達式的概念,數(shù)據(jù)類型及變量的定義方法; 掌握常用運算符的使用; 掌握程序的順序結(jié)構(gòu)、選擇結(jié)構(gòu)和循環(huán)結(jié)構(gòu)的使用; 掌握數(shù)組的定義及使用方法; 掌握基本的輸入輸出方法; 提示:不要去強記

    2024年02月02日
    瀏覽(33)
  • Spark大數(shù)據(jù)分析與實戰(zhàn)筆記(第二章 Spark基礎(chǔ)-05)

    Spark大數(shù)據(jù)分析與實戰(zhàn)筆記(第二章 Spark基礎(chǔ)-05)

    成長是一條必走的路路上我們傷痛在所難免。 在大數(shù)據(jù)處理和分析領(lǐng)域,Spark被廣泛應(yīng)用于解決海量數(shù)據(jù)處理和實時計算的挑戰(zhàn)。作為一個快速、可擴展且易于使用的分布式計算框架,Spark為開發(fā)人員提供了豐富的API和工具來處理和分析大規(guī)模數(shù)據(jù)集。 其中,Spark-Shell是Spar

    2024年02月03日
    瀏覽(100)
  • Spark大數(shù)據(jù)分析與實戰(zhàn)筆記(第二章 Spark基礎(chǔ)-01)

    Spark大數(shù)據(jù)分析與實戰(zhàn)筆記(第二章 Spark基礎(chǔ)-01)

    寧愿跑起來被拌倒無數(shù)次,也不愿規(guī)規(guī)矩矩走一輩子,就算跌倒也要豪邁的笑。 Spark于2009年誕生于美國加州大學(xué)伯克利分校的AMP實驗室,它是一個可應(yīng)用于大規(guī)模數(shù)據(jù)處理的統(tǒng)一分析引擎。Spark不僅計算速度快,而且內(nèi)置了豐富的API,使得我們能夠更加容易編寫程序。 Spark下

    2024年02月03日
    瀏覽(85)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包