繁体   English   中英

清除按钮.Android上的文本问题

[英]Clearing buttons .Text on Android issue

我正在为Android制作tic tac toe应用程序,当我运行清除按钮功能时:

    b1.setText("");
    b1.setEnabled(true);
    b1.setBackgroundColor(Color.LTGRAY);

为了清除按钮上的文字并使它们适用于新游戏,按钮之间的空间消失了,并且9个按钮的网格看起来像一个实心正方形。 当我单击按钮的位置时,仍然会显示“ X”,因此它们仍然存在,但是我想念的是使它们融合在一起的原因是什么?

获奖的组合代码是:

    if ((b1.getText() == "X") && (b2.getText() == "X") && (b3.getText() == "X"))
    {
        disableButtons();
        b1.setBackgroundColor(Color.RED);
        b2.setBackgroundColor(Color.RED);
        b3.setBackgroundColor(Color.RED);
        Toast.makeText(getApplicationContext(), "Congrats! You Win!", Toast.LENGTH_LONG).show();
    }

编辑这里是正在发生的事情的图像 第一

第二

您需要将背景图像设置回默认的9patch图像。 尝试这个:

b1.setBackgroundResource(android.R.drawable.btn_default);
b2.setBackgroundResource(android.R.drawable.btn_default);
b3.setBackgroundResource(android.R.drawable.btn_default);

也许删除这一行:

b1.setBackgroundColor(Color.LTGRAY);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM