How do I make a button invisible just after click?

狂风中的少年 提交于 2019-12-01 08:11:18

问题


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.


回答1:


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.




回答2:


It's quite simple. setVisibility(View.Invisible) inside OnClickListener() of the button




回答3:


put this line in your Button's on click method.

Button.setVisibility(View.INVISIBLE);

EDIT: if you make totally gone the Button view and then try

Button.setVisibility(View.GONE);



回答4:


Just use this in your OnClickListener:

button.setVisibility(View.INVISIBLE);

If you want it to be totally invisible and take up layout space use

button.setVisibility(View.GONE);



回答5:


you can do like this way.

yourbutton.setVisibility(Button.GONE);

This will be remove your button from your layout so other control will be used that space.

If you want to just hide and keep button size with another layout you can use

yourbutton.setVisibility(Button.INVISIBLE);


来源:https://stackoverflow.com/questions/7495088/how-do-i-make-a-button-invisible-just-after-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!