[英]What state is a view in after it is clicked (i.e. after the click is released)?
I have a clickable ImageView
with a background color, and what I want is that its background color is changed when it is touched/clicked and it should remain changed even after the click is released, until something else is clicked. 我有一个具有背景色的可单击ImageView
,我想要的是在触摸/单击时更改其背景色,并且即使在释放单击之后, 它也应保持更改状态 ,直到单击其他内容为止。 For that I am writing a state-list drawable . 为此,我正在编写一个状态列表drawable 。
I am using the pressed
state, which is while the view is being clicked. 我正在使用pressed
状态,也就是单击视图时。 I also want to know what state is the ImageView
in after the click is released (until something else is clicked). 我还想知道单击释放后(直到单击其他操作) ImageView
处于什么状态。
I am talking about the following states given here : 我在说这里给出的以下状态:
This is example !!! 这是例子!
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), drawable);
StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_pressed},
ResourcesCompat.getDrawable(getResources(), R.drawable.image_pressed, null));
states.addState(new int[]{android.R.attr.state_focused},
ResourcesCompat.getDrawable(getResources(), R.drawable.focused, null));
states.addState(new int[]{},
new BitmapDrawable(getResources(), bitmap));
imageView.setImageDrawable(states);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.