当前位置:   article > 正文

HarmonyOS(鸿蒙)——Text(文本,2024年最新HarmonyOS鸿蒙应用程序开发第三版课后答案

HarmonyOS(鸿蒙)——Text(文本,2024年最新HarmonyOS鸿蒙应用程序开发第三版课后答案

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新HarmonyOS鸿蒙全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img

img
img
htt

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上鸿蒙开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip204888 (备注鸿蒙)
img

正文

ohos:text_font=“HwChinese-medium”

/>

演示效果:

在这里插入图片描述

2.5 italic

| 属性名称 | 中文描述 | 取值 | 取值说明 | 使用案例 |

| — | — | — | — | — |

| italic | 文本是否斜体字体 | boolean类型 | 可以直接设置true/false,也可以引用boolean资源。 | ohos:italic=“true"ohos:italic=”$boolean:true" |

代码演示:

<Text

ohos:id=“$+id:text”

ohos:height=“match_content”

ohos:width=“match_content”

ohos:text=“李子捌”

ohos:text_size=“100px”

ohos:text_color=“#000000”

ohos:text_font=“sans-serif”

ohos:italic=“true”

/>

演示效果:

在这里插入图片描述

2.6 text_weight

| 属性名称 | 中文描述 | 取值 | 取值说明 | 使用案例 |

| — | — | — | — | — |

| text_weight | 字重 | integer类型 | 表示字体大小的integer类型。也可以引用integer资源。 | ohos:text_weight=“100"ohos:text_weight=”$integer:100" |

代码演示:

<Text

ohos:id=“$+id:text”

ohos:height=“match_content”

ohos:width=“match_content”

ohos:text=“Liziba”

ohos:text_size=“100px”

ohos:text_color=“#0000FF”

ohos:text_font=“serif”

ohos:italic=“true”

ohos:text_weight=“100”

/>

演示效果:

text_weight = 100

在这里插入图片描述

text_weight = 600

在这里插入图片描述

2.7 background_element

常用的背景如常见的文本背景、按钮背景,可以采用XML格式放置在graphic目录下。

在Project窗口,打开“entry > src > main > resources > base”,右键点击“graphic”文件夹,选择“New > File”,命名为“background_text.xml”,在background_text.xml中定义文本的背景。

代码演示:

<?xml version="1.0" encoding="UTF-8" ?>

<shape xmlns:ohos=“http://schemas.huawei.com/res/ohos”

ohos:shape=“rectangle”>

演示效果:

在这里插入图片描述

2.8 text_alignment

| 属性名称 | 中文描述 | 取值 | 取值说明 | 使用案例 |

| — | — | — | — | — |

| text_alignment | 文本对齐方式 | left | 表示文本靠左对齐。 | 可以设置取值项如表中所列,也可以使用“ |

| | | top | 表示文本靠顶部对齐。 | |

| | | right | 表示文本靠右对齐。 | |

| | | bottom | 表示文本靠底部对齐。 | |

| | | horizontal_center | 表示文本水平居中对齐。 | |

| | | vertical_center | 表示文本垂直居中对齐。 | |

| | | center | 表示文本居中对齐。 | |

| | | start | 表示文本靠起始端对齐。 | |

| | | end | 表示文本靠结尾端对齐。 | |

代码演示:

<Text

ohos:id=“$+id:text”

ohos:width=“300vp”

ohos:height=“100vp”

ohos:text=“Liziba”

ohos:text_size=“100px”

ohos:text_color=“#0000FF”

ohos:text_font=“serif”

ohos:italic=“true”

ohos:text_weight=“100”

ohos:left_margin=“15vp”

ohos:bottom_margin=“15vp”

ohos:right_padding=“15vp”

ohos:left_padding=“15vp”

ohos:text_alignment=“bottom|horizontal_center”

ohos:background_element=“$graphic:background_text”

/>

演示效果:

在这里插入图片描述

2.9 multiple_lines

| 属性名称 | 中文描述 | 取值 | 取值说明 | 使用案例 |

| — | — | — | — | — |

| multiple_lines | 多行模式设置 | boolean类型 | 可以直接设置true/false,也可以引用boolean资源。 | ohos:multiple_lines=“true"ohos:multiple_lines=”$boolean:true" |

代码演示:

<Text

ohos:id=“$+id:text”

ohos:width=“300px”

ohos:height=“match_content”

ohos:text=“LizibaLiziba”

ohos:text_size=“100px”

ohos:text_color=“#0000FF”

ohos:text_font=“serif”

ohos:italic=“true”

ohos:text_weight=“100”

ohos:max_text_lines=“2”

ohos:multiple_lines=“true”

ohos:background_element=“$graphic:background_text”

/>

演示效果:

在这里插入图片描述

2.10 max_text_lines

| 属性名称 | 中文描述 | 取值 | 取值说明 | 使用案例 |

| — | — | — | — | — |

| max_text_lines | 文本最大行数 | integer类型 | 可以直接设置整型数值,也可以引用integer资源。 | ohos:max_text_lines=“2"ohos:max_text_lines=”$integer:two" |

代码演示:

<Text

ohos:id=“$+id:text”

ohos:width=“300px”

ohos:height=“match_content”

ohos:text=“LizibaLizibaLiziba”

ohos:text_size=“100px”

ohos:text_color=“#0000FF”

ohos:text_font=“serif”

ohos:italic=“true”

ohos:text_weight=“100”

ohos:multiple_lines=“true”

ohos:max_text_lines=“2”

ohos:background_element=“$graphic:background_text”

/>

演示效果:

在这里插入图片描述

2.11 auto_font_size

| 属性名称 | 中文描述 | 取值 | 取值说明 | 使用案例 |

| — | — | — | — | — |

| auto_font_size | 是否支持文本自动调整文本字体大小 | boolean类型 | 可以直接设置true/false,也可以引用boolean资源。 | ohos:auto_font_size=“true"ohos:auto_font_size=”$boolean:true" |

代码演示:

方法一:

<Text

ohos:id=“$+id:text”

ohos:width=“300px”

ohos:height=“match_content”

ohos:text=“LizibaLizibaLiziba”

ohos:text_size=“100px”

ohos:text_color=“#0000FF”

ohos:text_font=“serif”

ohos:italic=“true”

ohos:text_weight=“100”

ohos:max_text_lines=“1”

ohos:auto_font_size=“true”

ohos:background_element=“$graphic:background_text”

/>

演示效果:

在这里插入图片描述

方法二:

<Text

ohos:id=“$+id:text”

ohos:width=“300px”

ohos:height=“match_content”

ohos:text=“L”

ohos:text_size=“100px”

ohos:text_color=“#0000FF”

ohos:text_font=“serif”

ohos:italic=“true”

ohos:text_weight=“100”

ohos:max_text_lines=“1”

ohos:auto_font_size=“true”

ohos:background_element=“$graphic:background_text”

/>

package com.liziba.demo.slice;

import com.liziba.demo.ResourceTable;

import ohos.aafwk.ability.AbilitySlice;

import ohos.agp.components.Component;

import ohos.agp.components.Text;

public class MainAbilitySlice extends AbilitySlice {

@Override

public void onStart(Intent intent) {

super.onStart(intent);

super.setUIContent(ResourceTable.Layout_ability_main);

// 每次点击修改内容,演示字体的自动调整

Text text = (Text) this.findComponentById(ResourceTable.Id_text);

text.setClickedListener(component -> {

text.setText(text.getText() + “L”);

});

}

}

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注鸿蒙)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

void onStart(Intent intent) {

super.onStart(intent);

super.setUIContent(ResourceTable.Layout_ability_main);

// 每次点击修改内容,演示字体的自动调整

Text text = (Text) this.findComponentById(ResourceTable.Id_text);

text.setClickedListener(component -> {

text.setText(text.getText() + “L”);

});

}

}

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip204888 (备注鸿蒙)
[外链图片转存中…(img-85kGs0tD-1713296527620)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/479974
推荐阅读
相关标签
  

闽ICP备14008679号