text = "Python文本加下划线"
underlined_text = '_' + text + '_'
print(underlined_text)
val builder = SpannableStringUtil.create(context!!)
            .setText("类似于HTML中的<li>标签的圆点效果")
            .setBullet(android.R.color.holo_green_dark)//添加圆点
            .setTextColor(android.R.color.black)
            .setText("\n设置文字左侧显示引用样式")
            .setQuote(android.R.color.holo_green_dark)
            .setText("\n设置下划线以及删除线")
            .setTextUnderline()//下划线
            .setTextStrikeThrough()//删除线
            .setTextColor(android.R.color.holo_red_dark)
            .setTextSize(20)
            .setTextStyle(Typeface.ITALIC)
            .setText("这个可以点击")
            .setTextColor(android.R.color.holo_green_dark)
            .setTextSize(21)
            .setTextStyle(Typeface.BOLD)//字体样式
            .setClick(tv_span1,{
                Log.e("data", it)
            },true)//设置点击
            .setText("这里设置下标")
            .setTextColor(android.R.color.holo_blue_dark)
            .setTextSubscript(6)//下标
            .setTextColor(android.R.color.holo_orange_dark)
            .setText("这里可以设置上标")
            .setScaleX(1.5f)
            .setTextColor(android.R.color.holo_green_dark)
            .setTextSuperscript(6)//上标
            .setTextColor(android.R.color.holo_blue_dark)
            .setDrawable(R.mipmap.ic_launcher,100,100)
            .setAlign(Layout.Alignment.ALIGN_OPPOSITE)
            .build()
        tv_span1.text = builder

        val builder1 = SpannableStringUtil.create(context!!)
            .setText("人的一生,有许多事情,是需要放在心里慢慢回味的,过去的就莫要追悔,一切向前看吧 任何打击都不足以成为你堕落的借口,即使你改变不了这个世界,你却依然可以改变自己,选择条正确的路永远走下去。")
            .setTextColor(android.R.color.holo_orange_dark)
            .setTextSize(17)
            .setTextLeadingMargin(30)//设置文本缩进
            .build()
        tv_span2.text = builder1
flowchart TD
    A(开始)
    B[创建TextView]
    C[设置下划线]
    D(结束)
    
    A --> B
    B --> C
    C --> D
text-decoration-line: none | [ underline || overline || line-through || blink ]
text-decoration-style: solid | double | dotted | dashed | wavy
text-decoration-color: 
text-decoration-thickness: auto | from-font | 
text-decoration-skip: none | [ objects || [ spaces | [ leading-spaces || trailing-spaces ] ] || edges || box-decoration ]
text-decoration-skip-ink: auto| none
其中text-decoration-line、text-decoration-style和text-decoration-color还可以简写成text-decoration:
text-decoration: || || 
除些之外,还新增了text-underline-position和text-underline-offset属性给文本设置下划线样式:
text-underline-position: auto | [ under || [ left | right ] ]
text-underline-offset: auto |
float pi1 = 3_.1415F;      // Invalid; cannot put underscores adjacent (before) to a decimal point
float pi2 = 3._1415F;      // Invalid; cannot put underscores adjacent (after) to a decimal point
long socialSecurityNumber1  = 999_99_9999_L;  // Invalid; cannot put underscores prior to an L suffix

int a1 = _52;              // This is an identifier, not a numeric literal, starts with underscore
int a2 = 5_2;              // OK (decimal literal)
int a3 = 52_;              // Invalid; cannot put underscores at the end of a literal
int a4 = 5_______2;        // OK (decimal literal)

int a5 = 0_x52;            // Invalid; cannot put underscores in the 0x radix prefix
int a6 = 0x_52;            // Invalid; cannot put underscores at the beginning of a number
int a7 = 0x5_2;            // OK (hexadecimal literal)
int a8 = 0x52_;            // Invalid; cannot put underscores at the end of a number

int a9 = 0_52;             // OK (octal literal)
int a10 = 05_2;            // OK (octal literal)
int a11 = 052_;            // Invalid; cannot put underscores at the end of a number
<resources>
<string name="hello"><u>phone:0123456</u></string>
<string name="app_name">MyLink</string>
</resources>
SpannableString content = new SpannableString("这是一段带有下划线的文本");
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
textView.setText(content);
import { StyleSheet } from 'react-native'

const styles = StyleSheet.create({
  mExchangeCopyText: {fontWeight: 'bold', color: '#1677ff', textDecorationLine: 'underline'}
})

export default styles
import { StyleSheet } from 'react-native'

const styles = StyleSheet.create({
  mExchangeCopyText: {fontWeight: 'bold', color: '#1677ff', textDecorationLine: 'underline'}
})

export default styles
pie
    title 实现步骤
    "步骤1" : 数据准备
    "步骤2" : 获取文本字符串
    "步骤3" : 添加下划线
    "步骤4" : 输出结果
​​UILabel * strikeLabel = [[UILabel alloc] initWithFrame:(CGRectMake(10, 10, 50, 30))];​​
​​NSString​​​ ​​*textStr = [​​​​NSString​​​ ​​stringWithFormat:​​​​@"%@元"​​​​, primeCost];​​

​​//中划线​​
​​NSDictionary​​​ ​​*attribtDic = @{​​​​NSStrikethroughStyleAttributeName​​​​: [​​​​NSNumber​​​ ​​numberWithInteger:​​​​NSUnderlineStyleSingle​​​​]};​​
​​NSMutableAttributedString​​​ ​​*attribtStr = [[​​​​NSMutableAttributedString​​​ ​​alloc]initWithString:textStr attributes:attribtDic];​​

​​// 赋值​​
​​strikeLabel.attributedText = attribtStr;​​

​​[​​​​self​​​​.view addSubview:strikeLabel];​​
>>> _
Traceback (most recent call last):
File "", line 1, in
NameError: name '_' is not defined
>>> 42
>>> _
>>> 'alright!' if _ else ':('
'alright!'
>>> _
'alright!'
>>> Class1.__doc__ # 类帮助信息 'Class1 Doc.' 
>>> Class1.__name__ # 类名称 'Class1' 
>>> Class1.__module__ # 类所在模块 '__main__' 
>>> Class1.__bases__ # 类所继承的基类 (<type 'object'>,)
 >>> Class1.__dict__ # 类字典,存储所有类成员信息。
 >>> Class1().__class__ # 实例实例化类信息 <class '__main__.Class1'> 
 >>> Class1().__module__ # 实例类型所在模块 '__main__' 
 >>> Class1.__dict__ # 类存储信息 {'__dict__': <attribute '__dict__' of 'People' objects>, '__module__': '__main__', '__weakref__': <attribute '__weakref__' of 'People' objects>, 'name': 'xxx',  '__doc__': '\n    Class1 Doc\n    '}
//属性
private  数据类型  属性名;   //建议增加相应的getter、setter方法

//方法


//构造方法
import javax.swing.*;
import java.awt.*;

public class UnderlineExample {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }

    private static void createAndShowGUI() {
        // 创建一个JFrame窗口
        JFrame frame = new JFrame("Underline Example");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // 创建一个JLabel组件
        JLabel label = new JLabel("<html><u>Hello, Java!</u></html>");
        label.setFont(new Font("Arial", Font.PLAIN, 16));

        // 将JLabel添加到JFrame中
        frame.getContentPane().add(label);

        // 设置JFrame的大小并显示
        frame.setSize(300, 200);
        frame.setVisible(true);
    }
}
gantt
    title 实现“Java给字符串加下划线”流程图

    section 准备工作
    定义字符串: done, 2021-01-01, 1d
    创建StringBuilder对象: done, after 定义字符串, 1d

    section 加下划线
    循环遍历字符串: done, 2021-01-03, 2d
    添加下划线: done, after 循环遍历字符串, 1d
TextView textView = findViewById(R.id.text_view);
String text = "这是一段需要添加下划线的文字";
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(new UnderlineSpan(), 0, text.length(), 0);
textView.setText(spannableString);
classDiagram
    class 小白 {
        +实现JAVA大写加下划线()
    }
    class 经验丰富的开发者 {
        +教会小白实现JAVA大写加下划线()
    }
    经验丰富的开发者 --|> 小白
  • 1
  • 2
  • 3
  • 4
  • 5