首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何移除/禁用安卓button[Beginner]

如何移除/禁用安卓button[Beginner]
EN

Stack Overflow用户
提问于 2013-11-10 23:35:39
回答 1查看 148关注 0票数 1

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

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

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

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

代码语言:javascript
复制
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,我使用了以下代码

代码语言:javascript
复制
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()“(隐藏函数)

如果有人能提供一些线索,我将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2013-11-11 00:05:12

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

如果在另一端你仍然想看到它们,但只是禁用它们,那么使用button.setEnabled(false)。

希望能有所帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19891572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档