Created
February 24, 2015 20:05
-
-
Save ZakTaccardi/2b6b4ddd36ccd0b6b000 to your computer and use it in GitHub Desktop.
Setting Background Drawable with Material Button
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
public BaseButton(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
TypedArray a = context.getTheme().obtainStyledAttributes( | |
attrs, | |
R.styleable.MaterialButton, | |
0, 0); | |
try { | |
colorButtonNormal = a.getInteger(R.styleable.MaterialButton_mbColorButtonNormal, Color.CYAN); | |
} finally { | |
a.recycle(); | |
} | |
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ | |
RippleDrawable draw = (RippleDrawable) getContext().getApplicationContext().getResources().getDrawable(R.drawable.raised_btn); | |
InsetDrawable inset = (InsetDrawable) draw.getDrawable(0); | |
GradientDrawable shape = (GradientDrawable) inset.getDrawable(); | |
shape.setColor(colorButtonNormal); | |
setBackground(draw); | |
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ | |
InsetDrawable draw = (InsetDrawable) getContext().getApplicationContext().getResources().getDrawable(R.drawable.raised_btn); | |
GradientDrawable shape = (GradientDrawable) draw.getDrawable(); | |
shape.setColor(colorButtonNormal); | |
setBackground(draw); | |
} else { | |
//todo | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment