[英]Android ImageButton Pressed State Doesn't Change
我以编程方式设置ImageButton的按下状态。
问题是当我按下它时,状态根本不会改变。 我尝试使用state_focused
和其他一些按钮,但是该按钮完全没有改变。 您知道为什么我的ImageButton在按下时没有更改其图像吗?
_pauseButton = new ImageButton(_context);
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] {},
getResources().getDrawable(R.drawable.pause));
stateListDrawable.addState(new int[] {android.R.attr.state_pressed},
getResources().getDrawable(R.drawable.pausepressed));
_pauseButton.setImageDrawable(stateListDrawable);
默认状态图像的确显示正确,但是当按下它时,没有任何变化。
我必须将默认状态设置为LAST。
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] {android.R.attr.state_pressed},
getResources().getDrawable(R.drawable.pausepressed));
stateListDrawable.addState(new int[] {},
getResources().getDrawable(R.drawable.pause));
看起来像android中的错误,我已经设置了一个报告:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.