文章目录

  • 1、Text 是什么?
  • 2、点击时:自动调节字体大小+动态增加文字
  • 3、跑马灯效果
  • 4、实战:一个标题栏和详细内容的界面
  • 5、Text 更多

1、Text 是什么?

简单:文本框组件
官方:Text是用来显示字符串的组件,在界面上显示为一块文本区域。

2、点击时:自动调节字体大小+动态增加文字


MainAbilitySlice.java

Text text = (Text) findComponentById(ResourceTable.Id_text);
// 设置自动调整规则
text.setAutoFontSizeRule(30, 100, 1);
// 设置点击一次增多一个"T"
text.setClickedListener(new Component.ClickedListener() {@Overridepublic void onClick(Component component) {text.setText(text.getText() + "T");}
});

ability_main.xml

<DependentLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:width="match_parent"ohos:height="match_content"><Textohos:id="$+id:text"ohos:width="match_parent"ohos:height="match_content"ohos:text="TextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextText"ohos:text_size="50fp"ohos:text_color="#0000FF"ohos:italic="true"ohos:text_alignment="vertical_center"ohos:text_weight="700"ohos:text_font="serif"ohos:background_element="$graphic:background_text"/>
</DependentLayout>

3、跑马灯效果

MainAbilitySlice.java

        Text text = (Text) findComponentById(ResourceTable.Id_text);
// 跑马灯效果text.setTruncationMode(Text.TruncationMode.AUTO_SCROLLING);
// 始终处于自动滚动状态text.setAutoScrollingCount(Text.AUTO_SCROLLING_FOREVER);
// 启动跑马灯效果text.startAutoScrolling();

ability_main.xml

<?xml version="1.0" encoding="utf-8"?>
<DependentLayoHutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:width="match_parent"ohos:height="match_content"ohos:background_element="$graphic:color_light_gray_element"><Textohos:id="$+id:text"ohos:width="75vp"ohos:height="match_content"ohos:text="TextText"ohos:text_size="28fp"ohos:text_color="#0000FF"ohos:italic="true"ohos:text_alignment="vertical_center"ohos:text_weight="700"ohos:text_font="serif"ohos:background_element="$graphic:background_text"/>
</DependentLayoHut>

4、实战:一个标题栏和详细内容的界面

ability_main.xml

<?xml version="1.0" encoding="utf-8"?>
<DependentLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:width="match_parent"ohos:height="match_content"ohos:background_element="$graphic:color_light_gray_element"><Textohos:id="$+id:text1"ohos:width="match_parent"ohos:height="match_content"ohos:text_size="25fp"ohos:top_margin="15vp"ohos:left_margin="15vp"ohos:right_margin="15vp"ohos:background_element="$graphic:background_text"ohos:text="Title"ohos:text_weight="1000"ohos:text_alignment="horizontal_center"/><Textohos:id="$+id:text2"ohos:width="match_parent"ohos:height="120vp"ohos:text_size="25fp"ohos:background_element="$graphic:background_text"ohos:text="Content"ohos:top_margin="15vp"ohos:left_margin="15vp"ohos:right_margin="15vp"ohos:bottom_margin="15vp"ohos:text_alignment="center"ohos:below="$id:text1"ohos:text_font="serif"/><Buttonohos:id="$+id:button1"ohos:width="75vp"ohos:height="match_content"ohos:text_size="15fp"ohos:background_element="$graphic:background_text"ohos:text="Previous"ohos:right_margin="15vp"ohos:bottom_margin="15vp"ohos:left_padding="5vp"ohos:right_padding="5vp"ohos:below="$id:text2"ohos:left_of="$id:button2"ohos:text_font="serif"/><Buttonohos:id="$+id:button2"ohos:width="75vp"ohos:height="match_content"ohos:text_size="15fp"ohos:background_element="$graphic:background_text"ohos:text="Next"ohos:right_margin="15vp"ohos:bottom_margin="15vp"ohos:left_padding="5vp"ohos:right_padding="5vp"ohos:align_parent_end="true"ohos:below="$id:text2"ohos:text_font="serif"/>
</DependentLayout>

下面这两个是自定义样式文件,需要放在 resources/base/graphic目录下,新建background_text.xml 与 color_light_gray_element.xml文件

background_text.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:shape="rectangle"><cornersohos:radius="20"/><solidohos:color="#878787"/>
</shape>

color_light_gray_element.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:shape="rectangle"><solidohos:color="#EDEDED"/>
</shape>

5、Text 更多

点击查看

Harmony OS — Text文本框相关推荐

  1. 关于input type=“text”文本框的 默认宽度

    当文本框的td设置宽度设置为百分比时,出现了一些没有搞懂的地方. 类选择设置td的width 为百分比时,通常 要定义父元素的宽度,在我的实战中父元素只能是table,给定table时. 而且这就是说 ...

  2. Unity 【Content Size Fitter】- 聊天气泡自动适配Text文本框大小

    通常在展示人物对话的时候文本的长度是不定的,因此会需要动态的调整对话内容文本框的背景图片的大小,这里以如下这种气泡框的对话为例: 实现该需求涉及到的内容包括Content Size Fitter组件的 ...

  3. 【100个 Unity踩坑小知识点】 | Unity中Text文本框 和 InputField文本输入框 内容换行问题

    Unity 小科普 老规矩,先介绍一下 Unity 的科普小知识: Unity是 实时3D互动内容创作和运营平台 . 包括游戏开发.美术.建筑.汽车设计.影视在内的所有创作者,借助 Unity 将创意 ...

  4. HTML5 实现给Text文本框中加入图片

    <style type="text/css">input{/*文本框的大小*/width:200px;height: 35px;/*图片*/background: ur ...

  5. ExtJs之Text文本框Text和文本域TextArea

    文本框Text //添加身份证号码校验var creditCard = Ext.create('Ext.form.field.Text', {fieldLabel : '身份证号',name : 'c ...

  6. 原生js赋值html,原生js文本框赋值点击文字给text文本框赋值表单提交

    特效描述:文本框赋值 文本框赋值表单 表单提交. 代码结构 1. HTML代码 菜单导航 时间日期 焦点图 tab标签 jquery特效 在线客服 官网 js代码 var x=["菜单导航& ...

  7. SwiftUI 控件之Text 文本框显示古诗(含demo)

    代码 import SwiftUIstruct ContentView: View {let gushi = """风急天高猿啸哀,渚清沙白鸟飞回.无边落木萧萧下,不尽长 ...

  8. 文字太多时给文本框添加滑动条——text + ContentSizeFitter + Scroll View

    文字少的时候,直接显示文字:文字多的时候,自动添加滑动条,拖动滑动条后查看全部文字. 1.字少的时候 2.字多的时候自动增加一个垂直滑动条 一.问题的来源 在一个固定区域显示文字,这些文字有时候会很多 ...

  9. java 文本框获取焦点,text在获取焦点时展示输入框原有内容

    text在获取焦点时显示输入框原有内容 想要这样一个效果:点击text获取焦点的时候,显示输入框原有内容. ------解决思路---------------------- 引用:那你在下面接一个di ...

  10. html隐藏input边框线,html中去掉文本框(input type=text)的边框或只显示下边框

    去掉: 只留下边框: CSS - input 只显示下边框 CSS 样式 :   border:none;   border-bottom: 1px solid #000 文本框input:text ...

最新文章

  1. 为什么你不应该自行更新 Drupal 网站?
  2. QTreeWidget
  3. java 方法执行结束局部变量释放_JAVA-方法在执行过程中,JVM的内存分配和变化情况,栈(stack)的情况浅析...
  4. 服务器每秒钟执行命令数量是什么_如何合理的评估上线服务器数量
  5. LeetCode 1120. 子树的最大平均值(DFS自底向上)
  6. Dockerfile中CMD和ENTRYPOINT的区别
  7. ES6学习(十一)—Class 的基本语法和继承
  8. Material使用09 MdCheckboxModule、MdMenuModule、MdTooltipModule
  9. oracle技术之一次RMAN备份报错的诊断过程(五)
  10. C语言如何打开shx文件,shx文件是什么 shx文件如何打开
  11. 简要介绍无刷电机的基础知识
  12. python 行列转换_行列转换的Mysql,Excel,Python解法
  13. 迅为4418开发板-驱动-以模块的方式编译内核驱动
  14. Python 实用的序列化和反序列化包marshmallow的使用指南
  15. 使用sqlyog连接阿里云rds数据库
  16. 读书笔记,《刻意练习》,第四章,黄金标准
  17. Kotlin 注解全解析
  18. [SARscape] 多时相SAR影像的应用 - 监督分类、提取水稻种植区 - 以Sentinel-1A数据为例
  19. “向前兼容”与“向后兼容”
  20. 最全英语单词下载地址

热门文章

  1. 【转】golang 结构体和方法
  2. JavaScript中值类型与引用类型
  3. ASP.NET没有魔法——ASP.NET MVC使用Area开发一个管理模块
  4. C#用链式方法表达循环嵌套
  5. 《神经网络和深度学习》系列文章七:实现我们的神经网络来分类数字(下)...
  6. Discuz = 7.2 SQL注入漏洞详情
  7. Linux系统下Lighttpd的安置设置-3
  8. Python匹配年月日和年月
  9. 万字长文带你从头构建文本分类器
  10. Kaggle数据增强攻略来了!不氪金实现50种语言互译