Created
September 28, 2015 13:34
-
-
Save felipearimateia/e0b150497aab95998bb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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