Android中对同一个TextView设置不同字体样式
生活随笔
收集整理的這篇文章主要介紹了
Android中对同一个TextView设置不同字体样式
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
這個只是做一個筆記,詳情見代碼:
代碼中的注釋也有說明。
TextView textView = (TextView) findViewById(R.id.textView1);SpannableStringBuilder sb = new SpannableStringBuilder("abcdefghijklmnopqrst."); // 包裝字體內(nèi)容ForegroundColorSpan fcs = new ForegroundColorSpan(getResources().getColor(R.color.yellow_orange)); // 設(shè)置字體顏色StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // 設(shè)置字體樣式AbsoluteSizeSpan ass = new AbsoluteSizeSpan(140); // 設(shè)置字體大小sb.setSpan(fcs, 0, 10, Spannable.SPAN_INCLUSIVE_INCLUSIVE);sb.setSpan(bss, 0, 20, Spannable.SPAN_INCLUSIVE_INCLUSIVE);sb.setSpan(ass, 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);textView.setText(sb);運行結(jié)果如下:
總結(jié)
以上是生活随笔為你收集整理的Android中对同一个TextView设置不同字体样式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android中最简单的分享功能
- 下一篇: Toast的另类应用及另类“拦截”Hom