how to use visible and invisible for a button in android

左心房为你撑大大i 提交于 2019-12-02 23:05:54

DONT USE -

donebutton.setVisibility(4);

Instead use the static constants for this:

donebutton.setVisibility(View.VISIBLE);

What exactly means

done.setVisibility(0);

Isn't is supposed to be

donebutton.setVisibility(View.GONE);

Here you go:

Button theButton = (Button)findViewById(R.id.theButton);
theButton.setVisibility(View.VISIBLE);
theButton.setBackgroundColor(Color.TRANSPARENT);

phoneButton.setOnClickListener(new OnClickListener()
{ 
 @Override
 public void onClick(View v)
 {
  // DO STUFF
 }
});

Hopefully this can help you to hide the buttons as well as show the buttons if they are hidden. You need to have three buttons in your layout file in order to follow this example.

Button b3 = (Button) findViewById(R.id.button3);
     @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        if (b1.isShown() && b2.isShown()) {
                            b1.setVisibility(View.GONE);
                            b2.setVisibility(View.GONE);

                        } else {
                            b1.setVisibility(View.VISIBLE);
                            b2.setVisibility(View.VISIBLE);
                        }
                    }
                });
Floern

Try onTouch() instead of onClick(): Clickable TextView in Android

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