简体   繁体   English

单击视图后(即释放单击后)视图处于什么状态?

[英]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 : 我在说这里给出的以下状态:

  • state_pressed state_pressed
  • state_focused state_focused
  • state_hovered state_hovered
  • state_selected state_selected
  • state_checkable state_checkable
  • state_checked state_checked
  • state_enabled state_enabled
  • state_activated state_activated
  • state_window_focused state_window_focused

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.

相关问题 : 当 getView() 为 null 时无法访问 Fragment View 的 LifecycleOwner,即在 onCreateView() 之前或 onDestroyView() 之后 - : Can't access the Fragment View's LifecycleOwner when getView() is null i.e., before onCreateView() or after onDestroyView() 再次单击后如何取消我单击的ListItem的选定状态? - How to cancel the selected state of the ListItem I have clicked after I click it again? 如何在 WorkManger 系统范围内注册一次定期工作请求(即启动或安装后) - How to register a periodic work request with WorkManger system-wide once (i.e. after boot or installation) 我们什么时候需要在大括号后面加分号? IE: ”};” - When do we need to put semicolon after curly brackets? i.e.: “};” 退出应用程序后(即按下主屏幕按钮),Android ProximityAlert无法保持活动状态 - Android ProximityAlert does not stay active after exiting app (i.e. pressing home button) 自定义按钮布局的状态选择器(即LinearLayout) - State selector for a custom button layout (i.e. LinearLayout) 每当单击按钮时,都不会在布局屏幕中以新的方式(例如0、1、2、3、4 ..)更新新的String,而是以一种模式(例如0、1、2、3、4 ..) - Updating the new String in the layout screen not randomly, but in a pattern(i.e. like 0,1,2,3,4..) whenever the button is clicked 发布使用它的Mediacodec后,可以在SurfaceView上绘制吗? - Can I draw on a surfaceView after I released the Mediacodec which is using it 单击后如何更改视图? - How to change view after click? Android Scroll View:如何在滚动视图中加载约2500个吉他和弦(即“Em7”) - Android Scroll View: How to load about 2500 guitar chords (i.e. “Em7”) into scroll view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM