So I’ve been looking around in forums for how to do this, but nothing I have found has worked. When I call setVisibility() on my image button, the button is unaffected. Below is my code that is in the onCreate method, and both buttons are showing up when I run the application. However, if I were to hardcode the attribute into the xml file, the visibility does change. Any ideas why this is happening?
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1 = new ImageButton(this);
btn1.setVisibility(GONE);
btn2 = new ImageButton(this);
btn2.setVisibility(GONE);
Change your code to :
and modify your main.xml: