4.24 | 冲刺day6
写了几个组件
@Composable fun AlignYourBodyElement( @DrawableRes drawable: Int, @StringRes text: Int, modifier: Modifier = Modifier, onClick: () -> Unit ) { Column (modifier=modifier, horizontalAlignment = Alignment.CenterHorizontally){ Image(painter = painterResource(drawable) , contentDescription =null , contentScale = ContentScale.Crop, modifier= Modifier .size(88.dp) .clip(CircleShape) .clickable { onClick() }) Text(text = stringResource(text), modifier= Modifier.paddingFromBaseline(top = 24.dp, bottom = 8.dp), style = MaterialTheme.typography.bodyMedium) } } @Preview(showBackground = true, backgroundColor = 0xFFF5F0EE) @Composable fun AlignYourBodyElementPreview() { MySootheTheme { AlignYourBodyElement( text = R.string.ab1_inversions, drawable = R.drawable.ab1_inversions, onClick = {}, modifier = Modifier.padding(8.dp) ) } } private val alignYourBodyData = listOf( DrawableStringPair( drawable = R.drawable.tel, text = R.string.tel, intent = Intent(Intent.ACTION_DIAL).apply { data = Uri.parse("tel:110") } ), DrawableStringPair( drawable = R.drawable.wechat, text = R.string.wechat, intent = Intent().apply { component = ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI") putExtra("LauncherUI.From.Scaner.Shortcut", true) flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP action = Intent.ACTION_VIEW } ), DrawableStringPair( drawable = R.drawable.tictok, text = R.string.tictok, intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) ), DrawableStringPair( drawable = R.drawable.ting, text = R.string.ting, intent = Intent(Intent.ACTION_VIEW, Uri.parse("baidumap://map/navi?query=石家庄铁道大学&src=andr.baidu.openAPIdemo")) ), DrawableStringPair( drawable = R.drawable.paypal, text = R.string.paypal, intent = Intent() ), DrawableStringPair( drawable = R.drawable.toutiao, text = R.string.toutiao, intent = Intent() ) ) @Composable fun AlignYourBodyRow( modifier: Modifier = Modifier, ) { val context = LocalContext.current LazyRow( horizontalArrangement = Arrangement.spacedBy(8.dp), contentPadding = PaddingValues(horizontal = 16.dp), modifier = modifier ) { items(alignYourBodyData) { item -> AlignYourBodyElement(item.drawable, item.text, onClick = { val intent= item.intent context.startActivity(intent) }) } } } @Preview(showBackground = true, backgroundColor = 0xFFF5F0EE) @Composable fun AlignYourBodyRowPreview() { //MySootheTheme { AlignYourBodyRow(onClick = {}) } }
浙公网安备 33010602011771号