How do I make a button invisible just after click?

前端 未结 5 1812
无人及你
无人及你 2021-01-14 12:01

I would like to know how to make a button visible but when clicked I want it to be invisible so it won\'t be shown at all.

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-14 12:04

    button.setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View v) {
                Button button = (Button) v;
                button.setVisibility(View.INVISIBLE);
            }
        });
    

    This makes it go invisible but still take up space in the layout, switching the last row for:

                    button.setVisibility(View.GONE);
    

    would make it "fold" and it will not only be invisible but won't take up space in the layuout either.

提交回复
热议问题