So currently I\'m putting an Easter egg inside my app and I want the Button
to be invisible, but when clicked(Rick roll). So far I can make it work when I say:
try making the text in the button " "...
myButton.setText(" ");
You can also disable the button (It will not be clickable).
In java code:
btn.setClickable(false);
In .xml layout:
android:clickable="false"
You can add an OnClickListener
to any View
, so try creating an ImageView
with a transparent image and attach your listener to that.
You can create any view, such as LinearLayout, as clickable. Make a LinearLayout with the same dimensions as the button and set it's onClick listener to whatever handles the event. Since it inherently isn't visible, it should hold the same effect.
In your layout, make your button have a specific width, like android:layout_width="40dp"
.
If your width is set to wrap_content
with a transparent background and no text, Android will measure that view as having a width of 0dp. You'll never be able to click on that.
This works properly for me:
btn.setClickable(false)
on GONE
visibility.btn.setClickable(true)
on VISIBLE
visibility.