温馨提示×

android button属性能否禁用按钮

小樊
131
2024-09-25 08:12:11
栏目: 编程语言

是的,Android Button组件的属性可以禁用按钮。可以使用以下两种方法来禁用Button:

方法一:在XML布局文件中设置button的enabled属性为false。例如:

<Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click Me!" android:enabled="false"/> 

方法二:在Java代码中调用button.setEnabled(false)。例如:

Button button = (Button) findViewById(R.id.button); button.setEnabled(false); 

无论使用哪种方法,Button都将被禁用,无法响应用户的点击事件。

0