Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. Chunk chunk1 = new Chunk("th");
  2. Chunk chunk2 = new Chunk("i", bold);
  3. Chunk chunk3 = new Chunk("s");
  4.  
  5. Paragraph p = new Paragraph();
  6. p.add(chunk1); p.add(chunk2); p.add(chunk3)
  7.  
  8. public SpannableString colorizeText(String text) {
  9. SpannableString spannableColor = new SpannableString(text);
  10. int x = 1;
  11. for(char letter : text.toCharArray()){
  12. spannableColor.setSpan(new ForegroundColorSpan(returnCorrectColor(letter)), x-1, x, 0);
  13. x++;
  14. }
  15. return spannableColor;
  16. }
  17.  
  18. private int returnCorrectColor(char letter) {
  19. String theLetter = Character.toString(letter);
  20. if (theLetter.contains("a")){
  21. return Color.BLUE;
  22. }
  23. else if(theLetter.contains("o")){
  24. return Color.GREEN;
  25. }
  26. return Color.RED;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement