禁用TextButton

use*_*325 6 libgdx

我试图禁用我编码的TextButton如下:

    // Setup new game button
    final TextButton newGameButton = new TextButton("New Game", style);
    newGameButton.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y,
                int pointer, int button) {
            Tyr.getInstance().setScreen(new GameScreen());
            AudioHelper.stopMusic();
            return true;
        }
    });
    table.add(newGameButton).spaceBottom(BUTTON_SPACE);
    table.row();
Run Code Online (Sandbox Code Playgroud)

但是,"setDisabled(true)"函数似乎不起作用.还有其他方法可以完成这项任务吗?

use*_*325 22

找到了解决方案:"newGameButton.setTouchable(Touchable.disabled);"

  • 这只是让我们无法点击按钮。但如何直观地表明它已被禁用。 (3认同)