如何删除/禁用android按钮[初学者]

如何删除/禁用android按钮[初学者],android,button,processing,Android,Button,Processing,首先,我要说的是,这是我第一次在Stackoverflow上发帖,因为我的大多数问题已经得到了这个伟大社区的回答 我正在尝试制作一个非常简单的程序,其中按钮被选中,并根据按钮保存一个字符串 我可以选择GUI 1上的按钮,然后显示我的GUI 2,但是我在GUI 1中创建的按钮仍然在后台,并且仍然处于启用状态 我想删除它们或完全禁用它们,这样我就不会有按钮重叠 Button want; Button dwant; Button eat; Button sleep; Button play; But

首先,我要说的是,这是我第一次在Stackoverflow上发帖,因为我的大多数问题已经得到了这个伟大社区的回答

我正在尝试制作一个非常简单的程序,其中按钮被选中,并根据按钮保存一个字符串

我可以选择GUI 1上的按钮,然后显示我的GUI 2,但是我在GUI 1中创建的按钮仍然在后台,并且仍然处于启用状态

我想删除它们或完全禁用它们,这样我就不会有按钮重叠

Button want;
Button dwant;

Button eat;
Button sleep;
Button play;
Button read;
Button swim;


boolean showGUI1 = true;
boolean showGUI2 = false;

color bgCol = color(255);

void setup()
{
 size(550, 900);

 want = new Button("Want",140,300,250,150); 
 dwant = new Button("Dont Want",140,590,250,150);

 eat = new Button("Eat",140,300,200,100); 
 sleep = new Button("Sleep",140,400,200,100); 
 play = new Button("Play",140,500,200,100); 
 read = new Button("Read",140,600,200,100); 
 swim = new Button("Swim",140,700,200,100); 

}

void draw()
{
  background(bgCol);

  if (showGUI1)
{
     want.display();
     dwant.display();
  }

  if (showGUI2)
  {
 eat.display();
 sleep.display();
 play.display();
 read.display();
 swim.display();

  }

}

    void mouseReleased()
    {
      if(want.mouseReleased())  
  {
    bgCol = color(255,0,0);
    choice= "Want";
    showGUI1 = false;
    showGUI2 = true;

  }

  if(dwant.mouseReleased())
  {
    bgCol = color(0,255,0);
    choice= "Dont Want";
    showGUI1 = false;
    showGUI2 = true;

   }

//action  GUI2 showing
    if(eat.mouseReleased())  
  {
    action= "Eat";

    showGUI2 = false;

  }

  if(sleep.mouseReleased())
  {
    action= "Sleep";

    showGUI2 = false;

  }

  if(play.mouseReleased())  
  {
    action= "Play";

    showGUI2 = false;

  }

  if(read.mouseReleased())
  {
    action= "Read";

    showGUI2 = false;

  }

  if(swim.mouseReleased())
  {
    action= "Swim";

    showGUI2 = false;

}
对于我的按钮,我使用以下代码

Button(String nm, int x, int y, int w, int h)
{
super(nm, x, y, w, h);
}

void display()
{
  if(currentImage != null)
  {
    float imgWidth = (extents.y*currentImage.width)/currentImage.height;

  pushStyle();
  imageMode(CORNER);
  tint(imageTint);
  image(currentImage, pos.x, pos.y, imgWidth, extents.y);
  stroke(bgColor);
  noFill();
  rect(pos.x, pos.y, imgWidth,  extents.y);
  noTint();
  popStyle();
}
else
{
  pushStyle();
  stroke(lineColor);
  fill(bgColor);
  rect(pos.x, pos.y, extents.x, extents.y);

  fill(lineColor);
  textAlign(CENTER, CENTER);
  text(name, pos.x + 0.5*extents.x, pos.y + 0.5* extents.y);
  popStyle();
}
}

我也可以使用ControlP5库来创建按钮,但即使这样,我也不知道如何激活“ControlP5.Controller:Button hide()”(隐藏函数)


如果有人能透露一些信息,我们将不胜感激。

好吧,要删除它们,您可以使用button.setVisibility(View.GONE),这将删除它们,并且它们不会占用任何布局空间。但是,如果要隐藏它们但保留它们占用的空间,请使用button.setVisibility(View.INVISIBLE)

如果在另一侧,您仍然希望看到它们,但只是禁用它们,请使用button.setEnabled(false)

希望有帮助

我尝试添加“import android.view.view;”以使用“button.setVisibility(view.go)”功能,但它给了我一个错误,即“软件包”android“不存在,您可能缺少一个库”我该如何处理?