Skip to content

Commit

Permalink
add ability to change text colour on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
Revedko committed Jan 2, 2015
1 parent 362f450 commit 46959ef
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion babushkatext/src/main/java/babushkatext/BabushkaText.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ public void reset() {
setText("");
}

/**
* Change text color of all pieces of textview.
*/
public void changeTextColor(int textColor) {
for (Piece mPiece : mPieces) {
mPiece.setTextColor(textColor);
}
display();
}

/**
* A Piece represents a part of the text that you want to style. Say for example you want this
* BabushkaText to display "Hello World" such that "Hello" is displayed in Bold and "World" is
Expand All @@ -227,8 +237,8 @@ public void reset() {
public static class Piece {

private String text;
private int textColor;
private final int textSize;
private final int textColor;
private final int backgroundColor;
private final float textSizeRelative;
private final int style;
Expand Down Expand Up @@ -263,6 +273,20 @@ public void setText(String text) {
this.text = text;
}


/**
* Sets the text color of this Piece. If you're creating a new Piece, you should do so using it's
* {@link babushkatext.BabushkaText.Piece.Builder}.
*
* Use this method if you want to change the text color of an existing Piece that is already
* displayed. After doing so, you MUST call {@code display()} for the changes to show up.
*
* @param color of text (it is NOT android Color resources ID, use getResources().getColor(R.color.colorId) for it)
*/
public void setTextColor(int textColor) {
this.textColor = textColor;
}

/**
* Builder of Pieces
*/
Expand Down

0 comments on commit 46959ef

Please sign in to comment.