Reputation: 429
Is there any way to change the size of the shadow based on whether the button is pressed or not? Is it possible to do it using only xml?
As far as I know, it's not possible with selectors.
Upvotes: 1
Views: 142
Reputation: 1759
The answer is probably no. Juan Andrés has asked a question like yours,but not got any response.
https://stackoverflow.com/questions/18470010/dimension-selector-in-xml
My compromised solution would be add event listener like this
findViewById(R.id.btn_result).setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
((Button) v).setShadowLayer(5, 5, 5, Color.BLUE);
break;
case MotionEvent.ACTION_UP:
((Button) v).setShadowLayer(2, 2, 2, Color.RED);
break;
default:
break;
}
return false;
}
});
look forward to a better answer
Upvotes: 1