Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* 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