I’m getting syntax errors when using ScaleDrawable(). I must be doing something wrong.
Any ideas?
2 errors I can’t quite fix.
This is what I have at the moment:
protected class testbuttonBackgroundDrawable extends LayerDrawable {
/** my aim - the image used as background for the custom view is increased in
*size by 25percent and then a yellow color filter is attached to it.
*This yellow image then has the original background image layered on top of it
*to create the effect of the image having a glow around it
*I want to use this later on for when the custom button has focus
*/
ColorFilter colourFilter = new LightingColorFilter(Color.YELLOW, 1);
ScaleDrawable resizedImage = new ScaleDrawable(background, 0, 1.25f, 1.25f);*
*error here is – Syntax error on token “;”, { expected after this token
nD = resizedImage.getDrawable();
nD.setColorFilter(colourFilter);
Drawable[] aD = new Drawable[2];
aD[0] = nD;
aD[1] = background;
LayerDrawable _highlightedDrawable = new LayerDrawable(aD);
//This will make the background image fade if the button is set to disabled
protected int _disabledAlpha = 100;
/**This is another scale drawable, this time used to shrink the background image of
*the custom button when it is pressed
*/
protected ScaleDrawable _pressedDrawable = new ScaleDrawable(background, 0, 0.75f, 0.75f);*
*error here is – “Syntax error, insert “}” to complete Block”
public testbuttonBackgroundDrawable(Drawable d) {
super(new Drawable[] { d });
}
@Override
protected boolean onStateChange(int[] states) {
boolean enabled = false;
boolean highlighted = false;
boolean pressed = false;
for (int state : states) {
if (state == android.R.attr.state_enabled)
enabled = true;
else if (state == android.R.attr.state_selected)
highlighted = true;
else if (state == android.R.attr.state_pressed)
pressed = true;
}
mutate();
if (enabled && highlighted) {
setBackgroundDrawable(_highlightedDrawable); // buttons need transparent backgrounds
} else if (!enabled) {
setColorFilter(null);
setAlpha(_disabledAlpha);
} else if (enabled && pressed){
setBackgroundDrawable(_pressedDrawable);
} else {
setColorFilter(null);
}
invalidateSelf();
return super.onStateChange(states);
}
}
}
Any help with fixing the errors would be appreciated.
I think I’m not using the ScaleDrawable constructor properly.
How do I do this correctly?
If that’s not the problem then any help would be appreciated.
fixed it!
The problem was that I was doing my calculations for my button states in the wrong section of the layer drawable class. This is it fixed: