android - Jetpack compose 中的 ClickableText 样式
问题描述
我正在尝试更改可点击文本的样式,主要是它的字体和颜色。
我现在正在使用:
text = AnnotatedString(stringResource(R.string.forgot_password)),
onClick = { offset ->
Log.d("ClickableText", "$offset -th character is clicked.")
} ```
This just using the default theme.
How can I apply a different color or font or fontsize ?
Thanks
解决方案
要使用字体,请定义一个fontFamily
属性,如下所示
private val Montserrat = FontFamily(
Font(R.font.montserrat_regular, FontWeight.Normal),
Font(R.font.montserrat_medium, FontWeight.Medium),
Font(R.font.montserrat_bold, FontWeight.Bold),
)
然后将其添加到您的排版中
val Typography = Typography(
h1 = TextStyle(
fontFamily = Montserrat,
fontSize = 96.sp,
fontWeight = FontWeight.Normal,
lineHeight = 117.sp,
letterSpacing = (-1.5).sp
),
添加到您的主题中
MaterialTheme(
colors = colors,
typography = Typography,
shapes = Shapes,
content = content
)
如果您随后在文本中使用这些样式,它将选择您指定的系列,或者您可以覆盖,像这样
Text(
text = "Sample text",
style = MaterialTheme.typography.body1.copy(
color = Color.Blue,
fontFamily = Montserrat,
),
)
推荐阅读
- c++ - 使用算法和/或函数库打印矢量元素
- for-loop - 使用 nunjucks 将字符串作为变量名传递给 for 循环
- sql - 从函数中选择
- azure - Azure 增量快照与完整快照大小相同?
- r - 结合 do.call() 和 debug() 打印所有参数内容
- postgresql - 如何在 postgreSQL 中将“2020-06-15”转换为“2020-06”(提供 BigQuery 示例)?
- r - 循环遍历一个数据框中的所有条目,以根据 R 中另一个数据框中的日期条件查找匹配项
- browser - 在浏览器中查看报告时,SSRS 报告编辑器中的行呈现不同
- makefile - 使用 make 的静态模式和条件
- excel - VBA用户表单文本框将上次修改的值设置为Texbox中的默认值