【一站式学会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里面的同名参数。

相关推荐
似霰3 小时前
AIDL Hal 开发笔记2----AIDL HAL 实例分析light hal
android·framework·hal
—Qeyser3 小时前
Flutter 颜色完全指南
android·flutter·ios
2501_916008895 小时前
iOS 上架需要哪些准备,账号、Bundle ID、证书、描述文件、安装测试及上传
android·ios·小程序·https·uni-app·iphone·webview
摘星编程7 小时前
React Native for OpenHarmony 实战:DatePickerAndroid 日期选择器详解
android·react native·react.js
花卷HJ9 小时前
Android 沉浸式全屏实践:主题 + 状态栏文字颜色完整方案
android
花卷HJ10 小时前
Android 项目中 BaseActivity 封装实践(支持 ViewBinding、PermissionUtils动态权限、加载弹窗和跳转动画)
android
消失的旧时光-194312 小时前
Android 接入 Flutter(Add-to-App)最小闭环:10 分钟跑起第一个混合页面
android·flutter
城东米粉儿12 小时前
android StrictMode 笔记
android
Zender Han12 小时前
Flutter Android 启动页 & App 图标替换(不使用任何插件的完整实践)
android·flutter·ios
童无极12 小时前
Android 弹幕君APP开发实战01
android