我已经创建了一个包含两个按钮的布局,下一个和上一个按钮。在按钮之间,我生成了一些动态视图。因此,当我第一次启动应用程序时,我想禁用“上一步”按钮,因为没有任何以前的视图。当没有更多的视图可显示时,我还想禁用“下一步”按钮。有什么办法可以禁用这些按钮吗?

发布于 2013-09-12 00:18:02
在Java中,一旦有了按钮的引用:
Button button = (Button) findviewById(R.id.button);要启用/禁用该按钮,可以使用以下任一方法:
button.setEnabled(false);
button.setEnabled(true);或者:
button.setClickable(false);
button.setClickable(true);由于您希望从一开始就禁用该按钮,因此可以在onCreate方法中使用button.setEnabled(false);。否则,在XML中,您可以直接使用:
android:clickable = "false"所以:
<Button
android:id="@+id/button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/button_text"
android:clickable = "false" />https://stackoverflow.com/questions/4384890
复制相似问题