Android Studio:按几个按钮



我想按几个按钮。例如,按下button1后可以按下button3(不按button1则不能按button3)。我想让它像下面的代码一样工作,但我不知道如何正确地编写它。

public void onClick(View view){
if(view.getId() == R.id.button1){
button1.setBackground(ContextCompat.getDrawable(this, R.drawable.design_btn_red_on));
if(view.getId() == R.id.button3){
//Blink button3
if(view.getId() == R.id.button10){
button3.setBackground(ContextCompat.getDrawable(this, R.drawable.design_btn_default_on));
}
}
}
if(view.getId() == R.id.button2){
button2.setBackground(ContextCompat.getDrawable(this, R.drawable.design_btn_green_on));
}
}

以上代码:按下button1使button1变红,再按下button3使button3闪烁。然后按下按钮10,按钮3变成白色。

对不起,我已经有一段时间没有使用android studio了不太确定这是否会起作用:默认情况下加载页面

For your button3:

Button button = findViewById(R.id.button)
button.setEnabled(false);

当按钮1被点击时,在if else期间

if (onclick button1 trigger)  //I can't recall what is the action button code
{
button.setEnabled(true);  //Trigger your button3 to be enabled
}
else
{
}

芬兰湾的科特林:

//禁用点击色。isClickable = false

//禁用按钮色。isEnabled = false

//启用点击色。isClickable = true

//启用按钮色。isEnabled = true

最新更新