使用 ScaleDrawable() 时出现语法错误。我一定做错了什么。有任何想法吗?
2个错误我无法完全修复。
这就是我目前所拥有的:
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);*
*此处的错误是 - 标记“;”上的语法错误,{ 预期在此标记之后
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);*
*这里的错误是-“语法错误,插入“}”以完成块”
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);
}
}
}
任何有关修复错误的帮助将不胜感激。
我想我没有正确使用 ScaleDrawable 构造函数。
我该如何正确地做到这一点?
如果这不是问题,那么任何帮助将不胜感激。