setEnabled() 和 setClickable(),有什么区别? [英] setEnabled() vs setClickable(), what is the difference?
问题描述
直到现在,当我想阻止用户按下按钮时,我会设置 button.setClickable(false);
并且通常将文本更改为某种灰色(让用户知道该按钮已禁用).今天我偶然发现了 setEnabled()
属性.
Until now, when I wanted to stop the user from pressing the button, I would set the button.setClickable(false);
and usually change the text to some kind of grey colour (to let the user know that the button is disabled). Today I stumbled upon the setEnabled()
property.
于是我去文档看下面的方法说明:
So I went to the documentation to see the method's explanation below:
setEnabled(boolean enabled)
Set the enabled state of this view.
这到底是什么意思?启用状态/可点击状态和禁用状态/不可点击状态有什么区别?有人可以解释一下我以前做的事情,使用 clickable 属性和使用 setEnabled()
属性有什么区别吗?什么时候应该使用?我搜索了 Stack Overflow,但找不到任何相关内容.
What does this even mean? What is the difference between enable state/clickable state and disabled state/not clickable state? Could someone please explain what is the difference between doing what I was doing previously, using the clickable property and using the setEnabled()
property? What should be used when? I searched Stack Overflow but could not find anything related.
推荐答案
这到底是什么意思?
What the hell is that mean?
在应用程序的上下文中,可以在给定的时间点启用或禁用小部件.启用的小部件具有响应事件的能力,例如击键或鼠标操作.无法响应此类事件的小部件被视为已禁用.禁用小部件的外观通常与启用小部件不同;禁用的小部件可能会以较浅的颜色绘制,或者可能会以某种方式在视觉上变得模糊.见右图示例.
In the context of an application, a widget may be enabled or disabled at a given point in time. An enabled widget has the capacity to respond to events, such as keystrokes or mouse actions. A widget that cannot respond to such events is considered disabled. The appearance of disabled widget is typically different from an enabled widget; the disabled widget may be drawn in a lighter color, or may be visually obscured in some way. See the image to the right for an example.
这个概念已经存在了几十年,可以在大多数 GUI 框架中找到.
This concept has been around for a couple of decades and can be found in most GUI frameworks.
启用状态/可点击状态和禁用状态/不可点击状态有什么区别?
what is the difference between enable state/clickable state and disabled state/ not clickable state?
在 Android 中,不可点击的小部件不会响应点击事件.禁用的小部件不仅不可点击,而且还直观地表明它已禁用.
In Android, a widget that is not clickable will not respond to click events. A disabled widget not only is not clickable, but it also visually indicates that it is disabled.
你是什么意思:..因为它使按钮在视觉上被禁用"?它如何在视觉上改变它?
what do you mean by: "..since it makes the Button visually "disabled"? how does it changes it visually?
使 Button
看起来和响应像 Button
的是它的背景,它是一个 StateListDrawable
.有一个用于禁用状态的特定图像.
What makes a Button
look and respond like a Button
is its background, which is a StateListDrawable
. There is a specific image used for the disabled state.
这篇关于setEnabled() 和 setClickable(),有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!