溫馨提示×

android button不可見怎么實現(xiàn)

小億
236
2023-10-12 07:19:06
欄目: 編程語言

要使Android按鈕不可見,可以使用以下方法之一:

  1. 在XML布局文件中設(shè)置按鈕的visibility屬性為"invisible",如下所示:
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:text="My Button" />
  1. 在Java代碼中設(shè)置按鈕的可見性為View.INVISIBLE,如下所示:
Button myButton = findViewById(R.id.myButton);
myButton.setVisibility(View.INVISIBLE);
  1. 在Java代碼中設(shè)置按鈕的可見性為View.GONE,如下所示:
Button myButton = findViewById(R.id.myButton);
myButton.setVisibility(View.GONE);

注意:通過設(shè)置按鈕的可見性為View.INVISIBLE或View.GONE,按鈕將不會可見,但是它仍然占據(jù)布局空間,而View.GONE會同時隱藏按鈕并且不占用布局空間。

0