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中将字体样式设置为粗体,斜体和下划线?...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 优秀的WEB应用程序
- 下一篇: HihoCoder 1245:王胖浩与三