Jetpack Compose系列-Text组件花式使用!,纯干货

     /** Alias for [W300] */
    @Stable
    val Light = W300
    /** The default font weight - alias for [W400] */
    @Stable
    val Normal = W400
    /** Alias for [W500] */
    @Stable
    val Medium = W500
    /** Alias for [W600] */
    @Stable
    val SemiBold = W600
    /**
     * A commonly used font weight that is heavier than normal - alias for [W700]
     */
    @Stable
    val Bold = W700
    /** Alias for [W800] */
    @Stable
    val ExtraBold = W800
    /** Alias for [W900] */
    @Stable
    val Black = W900

    /** A list of all the font weights. */
    internal val values: List<FontWeight> = listOf(
        W100,
        W200,
        W300,
        W400,
        W500,
        W600,
        W700,
        W800,
        W900
    ) 

看一下他们的显示效果:

@Composable
fun MyText() {
Column {
Text(
text = stringResource(R.string.my_text),
fontWeight = FontWeight.Thin,
)
Text(
text = stringResource(R.string.my_text),
fontWeight = FontWeight.ExtraLight
)
Text(
text = stringResource(R.string.my_text),
fontWeight = FontWeight.Light
)
Text(
text = stringResource(R.string.my_text),
fontWeight = FontWeight.Normal
)
Text(
text = stringResource(R.string.my_text),
fontWeight = FontWeight.Medium
)
Text(
text = stringResource(R.string.my_text),
fontWeight = FontWeight.SemiBold
)
Text(
text = stringResource(R.string.my_text),
fontWeight = FontWeight.Bold
)
Text(
text = stringResource(R.string.my_text),
fontWeight = FontWeight.ExtraBold
)
Text(
text = stringResource(R.string.my_text),
fontWeight = FontWeight.Black
)
}
}


![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0525313ac3b94ba9a920b1825a8451e5~tplv-k3u1fbpfcp-zoom-1.image)

##### fontFamily 更改字体

`fontFamily`可以更改字体,FontFamily为我们默认内置了5种字体,`Default`、`SansSerif`、`Serif`、`Monospace`、`Cursive`。

@Composable
fun MyText() {
Column {
Text(
text = stringResource(R.string.my_text),
fontFamily = FontFamily.Default,
)
Text(
text = stringResource(R.string.my_text),
fontFamily = FontFamily.SansSerif
)
Text(
text = stringResource(R.string.my_text),
fontFamily = FontFamily.Serif
)
Text(
text = stringResource(R.string.my_text),
fontFamily = FontFamily.Monospace
)
Text(
text = stringResource(R.string.my_text),
fontFamily = FontFamily.Cursive
)
}
}


![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/ab316bf80b1644f1bf7ed78249ab0c84~tplv-k3u1fbpfcp-zoom-1.image)

##### letterSpacing 更改文字间距

`letterSpacing`更改文字间距,更确切的说是更改字符间距,因为如果是英文的话,不会按单词来设置间距,而是按字母。

@Composable
fun MyText() {
Text(
text = stringResource(R.string.my_text),
letterSpacing = 10.sp,
)
}


![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/19772b2ca7654e04b5595b7bba90ab5f~tplv-k3u1fbpfcp-zoom-1.image)

##### textDecoration 文字装饰器

`textDecoration`可以给文字装饰下划线和中划线。默认提供了三个值:

*   `None`: 无装饰效果
*   `LineThrough`: 添加中划线
*   `Underline`: 添加下划线

@Composable
fun MyText() {
Column {
Text(
text = stringResource(R.string.my_text),
textDecoration = TextDec

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值