唯客微博客

专注于计算机,嵌入式领域的技术

0%

Jetpack Compose组件-图标(Icon)

Jetpack Compose组件-图标(Icon)

图标(Icon)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@Composable
@NonRestartableComposable
fun Icon(
// 位图对象,可以显示 JPG,PNG 等格式的图标
bitmap: ImageBitmap,
// 无障碍功能, 图标描述信息
contentDescription: String?,
// 修饰符
modifier: Modifier = Modifier,
// 设置图标颜色
tint: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current)
): Unit

@Composable
fun Icon(
// 画笔,可以使用画笔在 Canvas 上直接绘制图标,可以通过 res/ 下的图片资源来设置图标
painter: Painter,
// 无障碍功能, 图标描述信息
contentDescription: String?,
// 修饰符
modifier: Modifier = Modifier,
// 设置图标颜色
tint: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current)
): Unit

@Composable
@NonRestartableComposable
fun Icon(
// 矢量图对象,可以显示 SVG 格式的图标
imageVector: ImageVector,
// 无障碍功能, 图标描述信息
contentDescription: String?,
// 修饰符
modifier: Modifier = Modifier,
// 设置图标颜色
tint: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current)
): Unit
1
2
3
4
5
6
7
8
9
10
Icon(imageVector = ImageVector.vectorResource(
id = R.drawable.ic_svg, contentDescription = "矢量图资源")

Icon(bitmap = ImageBitmap.imageResource(
id = R.drawable.ic_png), contentDescription = "图片资源")

Icon(painter = painterResource(
id = R.drawable.ic_both), contentDescription = "任意类型资源")

Icon(imageVector = Icons.Default.Deck, contentDescription = null, tint = Color.Red)
-------------本文结束感谢您的阅读-------------

本文标题:Jetpack Compose组件-图标(Icon)

文章作者:Vinx

发布时间:2023年01月12日 - 11:15

最后更新:2023年09月18日 - 11:40

原始链接:https://blog.vinkvin.com/post/60/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。