提供自定義TextViews風格更簡單的方法:BabushkaText

jopen 10年前發布 | 22K 次閱讀 Android開發 移動開發 BabushkaText

BabushkaText提供一種更簡單的方法來自定義TextViews風格。BabushkaText是一個自定義TextView,讓你能夠通過Spannables來定制文本部分的風格。但無需直接處理Spannable的麻煩。

  • Create complex style structures for your text without having to add multiple TextViews to your view hierarchy.
  • Eliminate setSpan(Object what, int start, int end, int flags) calls by using more convenient methods such as .style(Typeface.BOLD), .superscript() and others.
  • </ul>

    example.png

            BabushkaText babushka = (BabushkaText)findViewById(R.id.babushka_text);
    
            // Add the first piece "Central Park"
            babushka.addPiece(new BabushkaText.Piece.Builder("Central Park, NY\n")
                    .textColor(Color.parseColor("#414141"))
                    .build());
    
            // Add the second piece "1.2 mi"
            babushka.addPiece(new BabushkaText.Piece.Builder("1.2 mi ")
                    .textColor(Color.parseColor("#0081E2"))
                    .textSizeRelative(0.9f)
                    .build());
    
            // Add the third piece "from here"
            babushka.addPiece(new BabushkaText.Piece.Builder("from here")
                    .textColor(Color.parseColor("#969696"))
                    .textSizeRelative(0.9f)
                    .build());
    
            // Display the final, styled text
            babushka.display();

    項目主頁:http://www.baiduhome.net/lib/view/home/1417443546697

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!