【一站式学会compose】 Android UI体系之 Text的使用和介绍

(1)Text 属性介绍:基本功能是显示一段文字

kotlin 复制代码
fun Text(
    text: String, // 文本内容
    modifier: Modifier = Modifier, // 修饰,一般背景,大小在这里设置
    color: Color = Color.Unspecified, // 颜色
    fontSize: TextUnit = TextUnit.Unspecified, // 字体大小
    fontStyle: FontStyle? = null, // 字体的变体,如斜体
    fontWeight: FontWeight? = null, // 粗细
    fontFamily: FontFamily? = null, // 字体
    letterSpacing: TextUnit = TextUnit.Unspecified, // 文字间距
    textDecoration: TextDecoration? = null, // 文本的装饰,如下划线
    textAlign: TextAlign? = null,// 文本的对其方式
    lineHeight: TextUnit = TextUnit.Unspecified, // 行间距
    overflow: TextOverflow = TextOverflow.Clip, // 文本移除的视觉效果
    softWrap: Boolean = true, // 控制文本是否能够换行
    maxLines: Int = Int.MAX_VALUE, // 最大行数
    minLines: Int = 1,// 最小行数
    onTextLayout: ((TextLayoutResult) -> Unit)? = null, //。文本花边之后的回掉
    style: TextStyle = LocalTextStyle.current // 文本样式
)

(2) 如何显示制定字符串

kotlin 复制代码
Text("hello world")
Text(stringResource(R.string.app_name))

(3)Text的style属性的使用

你可以设置的属性有:

kotlin 复制代码
        color: Color = Color.Unspecified,
        fontSize: TextUnit = TextUnit.Unspecified,
        fontWeight: FontWeight? = null,
        fontStyle: FontStyle? = null,
        fontSynthesis: FontSynthesis? = null,
        fontFamily: FontFamily? = null,
        fontFeatureSettings: String? = null,
        letterSpacing: TextUnit = TextUnit.Unspecified,
        baselineShift: BaselineShift? = null,
        textGeometricTransform: TextGeometricTransform? = null,
        localeList: LocaleList? = null,
        background: Color = Color.Unspecified,
        textDecoration: TextDecoration? = null,
        shadow: Shadow? = null,
        textAlign: TextAlign? = null,
        textDirection: TextDirection? = null,
        lineHeight: TextUnit = TextUnit.Unspecified,
        textIndent: TextIndent? = null

案例:

kotlin 复制代码
  Text(
        stringResource(R.string.app_name),
        style = TextStyle(color = Color.Blue, fontWeight = FontWeight.Bold, fontSize = 50.sp)
    )

特别注意:style参数可以在text的构造函数中直接指定,一旦指定,Text的参数会覆盖style里面的同名参数。

相关推荐
介一安全2 小时前
【Frida Android】实战篇18:Frida检测与绕过——基于内核指令的攻防实战
android·网络安全·逆向·安全性测试·frida
冬奇Lab2 小时前
Android稳定性基础:系统架构与关键机制
android·系统架构
李坤林2 小时前
Android ION Memory Manager 深度分析
android
Digitally2 小时前
iPhone 无法向安卓设备发送图片:轻松解决
android·ios·iphone
Digitally2 小时前
如何从 Infinix 手机中删除联系人
android
jingling5552 小时前
uni-app 安卓端完美接入卫星地图:解决图层缺失与层级过高难题
android·前端·javascript·uni-app
草莓熊Lotso2 小时前
C++ 智能指针完全指南:原理、用法与避坑实战(从 RAII 到循环引用)
android·java·开发语言·c++·人工智能·经验分享·qt
代码or搬砖11 小时前
String字符串
android·java·开发语言
59803541513 小时前
【java工具类】小数、整数转中文大写
android·java·开发语言