android - 如何设置按钮不可见android

标签 android button invisible

所以我试图让 A 按钮不可见,我先在论坛上搜索答案并尝试了,但它不起作用。

int level=0;
    try{
        String FILENAME = "TowerFile";
        FileInputStream fos = openFileInput(FILENAME);
        byte[] b = new byte[1];
        fos.read(b);
        fos.close();
        if(new String(b).equalsIgnoreCase("1")){
            level=1;
        }
        if(new String(b).equalsIgnoreCase("2")){
            level=2;
        }
        if(new String(b).equalsIgnoreCase("3")){
            level=3;
        }
        if(new String(b).equalsIgnoreCase("4")){
            level=4;
        }
        if(new String(b).equalsIgnoreCase("5")){
            level=5;
        }
    }catch (java.io.FileNotFoundException e) {
    } catch (IOException e) {
            e.printStackTrace();
    }

    Button button1 = (Button) findViewById(R.id.button1);
    Button button2 = (Button) findViewById(R.id.button2);
    Button button3 = (Button) findViewById(R.id.button3);
    Button button4 = (Button) findViewById(R.id.button4);
    Button button5 = (Button) findViewById(R.id.button5);



    if(level==1){
        button1.setVisibility(View.INVISIBLE);
    }

所以我首先从我的文件中获取 A variabel,然后我想根据输出使 A 按钮不可见。我从我的文件中得到了赖特编号,但它没有做任何事情,我也做了 0 并消失了,但没有任何效果

最佳答案

buttonName.setVisibility(View.GONE);

这比 (View.INVISIBLE) 更好,因为按钮不会从布局中获得任何空间。如果你想让按钮再次可见,只需使用:

buttonName.setVisibility(View.VISIBLE);

关于android - 如何设置按钮不可见android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9991065/

相关文章:

android - 旋转后无法恢复滚动位置(RecyclerView)

python - 无法使 Sprite 在pygame中不可见

c++ - 如何设置 QDialog 在 exec() 方法上不可见?

android将数据库从内部存储复制到外部存储返回空数据库

java - 使用 LibGDX 加载音乐时出现此错误的原因是什么?

Python子进程杀死

java - Android 硬件菜单按钮代码无法正常工作!需要帮忙

java - 使用 InputHandler 在 libGdx 中创建播放按钮

jquery - Google INVISIBLE reCaptcha + jQuery validate() 问题

Android 应用程序在实现 Google Firebase 后卡住