所以我试图让 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/