Skip to content

Instantly share code, notes, and snippets.

@felipearimateia
Created September 28, 2015 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipearimateia/e0b150497aab95998bb5 to your computer and use it in GitHub Desktop.
Save felipearimateia/e0b150497aab95998bb5 to your computer and use it in GitHub Desktop.
/**
* Created by felipearimateia on 02/11/14.
*/
public class TextViewLine extends TextView{
private BorderDrawable borderDrawable;
private int selectColor;
private int backgroundColor;
public TextViewLine(Context context) {
super(context);
}
public TextViewLine(Context context, AttributeSet attrs) {
super(context, attrs);
configAttributeSet(context, attrs);
}
public TextViewLine(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
configAttributeSet(context, attrs);
}
private void configAttributeSet(Context context, AttributeSet attrs) {
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TextViewLine, 0, 0);
try {
selectColor = a.getColor(R.styleable.TextViewLine_selectColor, Color.WHITE);
backgroundColor = a.getColor(R.styleable.TextViewLine_backgroundColor, Color.TRANSPARENT);
}finally {
a.recycle();
}
}
@Override
public void setSelected(boolean selected) {
super.setSelected(selected);
if (selected) {
addBoard();
}
else {
setBackgroundColor(backgroundColor);
}
}
private void addBoard() {
if(borderDrawable == null)
borderDrawable = new BorderDrawable();
borderDrawable.setBottomBorder(4, selectColor);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
setBackgroundDrawable(borderDrawable);
}
else {
setBackground(borderDrawable);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment