码迷,mamicode.com
首页 > 其他好文 > 详细

e655. 混合风格的文本

时间:2018-09-02 23:52:13      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:风格   man   amp   font   this   ted   layout   enter   new   

This example applies a new font and background color to a part of the text. You can apply styles to as many parts of the text as you need. See TextAttributes for available styles.

    // Apply styles to text
    AttributedString astr = new AttributedString("aString");
    astr.addAttribute(TextAttribute.FONT, font, start, end);
    astr.addAttribute(TextAttribute.BACKGROUND, color, start, end);
    
    // Draw mixed-style text
    TextLayout tl = new TextLayout(astr.getIterator(), g2d.getFontRenderContext());
    tl.draw(g2d, x, y);

 

Related Examples

e655. 混合风格的文本

标签:风格   man   amp   font   this   ted   layout   enter   new   

原文地址:https://www.cnblogs.com/borter/p/9575451.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!