How can I remove a button or make it invisible in Android?


Question

How can I remove a button in Android, or make it invisible?

1
147
10/24/2012 12:23:50 PM

Accepted Answer

Set button visibility to GONE (button will be completely "removed" -- the buttons space will be available for another widgets) or INVISIBLE (button will became "transparent" -- its space will not be available for another widgets):

View b = findViewById(R.id.button);
b.setVisibility(View.GONE);

or in xml:

<Button ... android:visibility="gone"/>
358
5/20/2016 9:13:44 PM

First make the button invisible in xml file.Then set button visible in java code if needed.

Button resetButton=(Button)findViewById(R.id.my_button_del);
resetButton.setVisibility(View.VISIBLE); //To set visible

Xml:

<Button
android:text="Delete"
android:id="@+id/my_button_del"
android:layout_width="72dp" 
android:layout_height="40dp"
android:visibility="invisible"/>

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon