日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android 字体加下划线,如何在Android TextView中将字体样式设置为粗体,斜体和下划线?...

發布時間:2023/12/15 Android 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 字体加下划线,如何在Android TextView中将字体样式设置为粗体,斜体和下划线?... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我想讓TextView的內容變得粗體,斜體和下劃線。 我嘗試了如下代碼而且它能夠工做,但沒有強調。 android

我該怎么作? 任何快速的想法? 編程

#1樓

這是添加下劃線的簡單方法,同時保持其余設置: 網絡

textView.setPaintFlags(textView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

#2樓

或者像Kotlin同樣: 字體

val tv = findViewById(R.id.textViewOne) as TextView

tv.setTypeface(null, Typeface.BOLD_ITALIC)

// OR

tv.setTypeface(null, Typeface.BOLD or Typeface.ITALIC)

// OR

tv.setTypeface(null, Typeface.BOLD)

// OR

tv.setTypeface(null, Typeface.ITALIC)

// AND

tv.paintFlags = tv.paintFlags or Paint.UNDERLINE_TEXT_FLAG

或者在Java中: spa

TextView tv = (TextView)findViewById(R.id.textViewOne);

tv.setTypeface(null, Typeface.BOLD_ITALIC);

// OR

tv.setTypeface(null, Typeface.BOLD|Typeface.ITALIC);

// OR

tv.setTypeface(null, Typeface.BOLD);

// OR

tv.setTypeface(null, Typeface.ITALIC);

// AND

tv.setPaintFlags(tv.getPaintFlags()|Paint.UNDERLINE_TEXT_FLAG);

保持簡單,一行:) code

#3樓

style="?android:attr/listSeparatorTextViewStyle

經過制做這種風格,你能夠實現強調

#4樓

若是您正在從文件或網絡中讀取該文本。 orm

您能夠經過向所提到的文本添加HTML標記來實現它 字符串

This text is italic and bold

and underlined bolditalicunderlined

而后,您能夠使用將HTML字符串處理為可顯示樣式文本的HTML類。 get

// textString is the String after you retrieve it from the file

textView.setText(Html.fromHtml(textString));

#5樓

Programmatialy: 字符串處理

您能夠使用setTypeface()方法以編程方式執行:

下面是默認字體的代碼

textView.setTypeface(null, Typeface.NORMAL); // for Normal Text

textView.setTypeface(null, Typeface.BOLD); // for Bold only

textView.setTypeface(null, Typeface.ITALIC); // for Italic

textView.setTypeface(null, Typeface.BOLD_ITALIC); // for Bold and Italic

若是要設置自定義字體:

textView.setTypeface(textView.getTypeface(), Typeface.NORMAL); // for Normal Text

textView.setTypeface(textView.getTypeface(), Typeface.BOLD); // for Bold only

textView.setTypeface(textView.getTypeface(), Typeface.ITALIC); // for Italic

textView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC); // for Bold and Italic

XML:

您能夠直接在XML文件中設置:

android:textStyle="normal"

android:textStyle="normal|bold"

android:textStyle="normal|italic"

android:textStyle="bold"

android:textStyle="bold|italic"

總結

以上是生活随笔為你收集整理的android 字体加下划线,如何在Android TextView中将字体样式设置为粗体,斜体和下划线?...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。