4、中划线、下划线

一、中划线

1、在布局中无法完成,需要去Activity实现

2、布局代码

<TextView
android:id="@+id/tv_4"
android:text="小秦同学在上学"
android:layout_marginTop="20dp"
android:textColor="#000000"
android:textSize="36sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

3、activity设置

     3.1声明TextView 

    private TextView mtv4;

     3.2代码

    //添加中划线
//强制转换
mtv4=(TextView) findViewById(R.id.tv_4);
mtv4.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
mtv4.getPaint().setAntiAlias(true);//去除锯齿

二、下划线

常规方法

布局代码:

<TextView
android:id="@+id/tv_5"
android:text="天哥在奔跑"
android:textColor="#000000"
android:textSize="36sp"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

Activity代码:

   *声明TextView

    private TextView mtv5;

   *设置下划线

    //设置下划线
mtv5=(TextView) findViewById(R.id.tv_5);
mtv5.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);

HTML方法:

布局代码:

//注意此时text里面是没有值
<TextView
android:id="@+id/tv_6"
android:text=""
android:textSize="36sp"
android:textColor="#000000"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>

Activity代码:

   *声明TextView

   private TextView mtv6;

   *设置下划线

   //设置下划线
mtv6=(TextView)findViewById(R.id.tv_6);
mtv6.setText(Html.fromHtml("<u>小秦同学在上学</u>"));
posted @   小秦同学在上学  阅读(109)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示