其他活动的Android RadioButton颜色更改

其他活动的Android RadioButton颜色更改,android,android-activity,colors,Android,Android Activity,Colors,我是Android编程新手,我的项目有一个问题。 我想改变我开始活动的背景(这是一个反应游戏)。 所有设置(背景颜色、声音等)都有额外的活动, 我在这部分迷路了:/I我想在设置活动中选择一种颜色(蓝色和红色),并在开始活动中将背景更改为所选颜色。这是活动设置的代码,颜色的单选按钮位于一个组(RadioGroup_Color)中。有人知道怎么解决这个问题吗 当我执行此代码时,总是出现错误: public class activity_settings extends Activity { @Ove

我是Android编程新手,我的项目有一个问题。 我想改变我开始活动的背景(这是一个反应游戏)。 所有设置(背景颜色、声音等)都有额外的活动, 我在这部分迷路了:/I我想在设置活动中选择一种颜色(蓝色和红色),并在开始活动中将背景更改为所选颜色。这是活动设置的代码,颜色的单选按钮位于一个组(RadioGroup_Color)中。有人知道怎么解决这个问题吗

当我执行此代码时,总是出现错误:

public class activity_settings extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_activity_settings);
    colorchange();
}

public void colorchange() {
    final RadioGroup radioGroup = (RadioGroup) findViewById(R.id.RadioGroup_Color);

    final RelativeLayout background = (RelativeLayout) findViewById(R.id.start);

    final Button button_save = (Button) findViewById(R.id.button_save);
    button_save.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            changeOption(background);

        }
    });

    final RadioButton changeToBlue = (RadioButton) findViewById(R.id.button_blue);
    changeToBlue.setOnCheckedChangeListener(new radioGroup.OnCheckedChangeListener() {
        public void onClick(View v) {
            changeToBlue(background);

        }
    });

    final RadioButton changeToRed = (RadioButton) findViewById(R.id.button_red);
    changeToRed.setOnCheckedChangeListener(new radioGroup.OnCheckedChangeListener() {
        public void onClick(View v) {
            changeToRed(background);

        }
    });

}

public void changeOption(RelativeLayout background) {
    if (background.isEnabled()) {
        background.setEnabled(false);
    } else {
        background.setEnabled(true);

    }
}

public void changeToBlue(RelativeLayout background) {
    background.setBackgroundColor(0x0000FF00);
    background.invalidate();

}
public void changeToRed(RelativeLayout background) {
    background.setBackgroundColor(0x0000FF00);
    background.invalidate();

}




@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_activity_settings, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}}
错误消息:

Error:(38, 91) error: <anonymous com.example.clecks.reaction_game.activity_settings$2> is not abstract and does not override abstract method onCheckedChanged(CompoundButton,boolean) in OnCheckedChangeListener

让我们看看您的实际错误:

错误:(38,91)错误:不是抽象的,并且不会重写OnCheckedChangeListener中onCheckedChanged(CompoundButton,boolean)的抽象方法

oncheckedchangedListener
上缺少
onCheckedChanged(复合按钮,布尔值)
实现

查看您的代码,我可以看到两个
OnCheckedChangeListener
实现;这里有一个:

changeToBlue.setOnCheckedChangeListener(new radioGroup.OnCheckedChangeListener() {
    public void onClick(View v) {
        changeToBlue(background);

    }
});
这些实现是错误的。

您需要覆盖
onCheckedChanged(复合按钮,布尔值)
onClick(视图)
oncheckedchangedlistener
中不存在)作为错误报告。另外,
new radioGroup.OnCheckedChangeListener
错误并导致主要错误

用以下方法修复代码:

changeToBlue.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton c, boolean b) {
        changeToBlue(background);
    }
});

看一下简单的官员。

谢谢,我完全忽略了这一行!但现在我得到了另一个错误:error:(8,8)error:com.example.clecks.reaction\u game.OnCheckedChangeListener不是抽象的,并且不会覆盖android.widget.CompoundButton.OnCheckedChangeListener中的抽象方法onCheckedChanged(CompoundButton,boolean)。另外,使用
newcompoundButton.OnCheckedChangeListener
而不是
new radioGroup.OnCheckedChangeListener
(这不是抽象的),一切都应该很好。我已经更改了所有实现。。。仍然得到错误-不知道要做什么:(链接到新代码:我正在使用您的代码,它可以工作。当前错误到底是什么?不能是同一个错误…仍然是一样的:错误:(8,8)错误:com.example.clecks.reaction\u game.oncheckedchangedListener不是抽象的,并且不会重写onCheckedChanged(CompoundButton,boolean)的抽象方法在android.widget.CompoundButton.OnCheckedChangeListener中。当我单击它时,会打开一个名为“OnCheckedChangeListener.java:公共类OnCheckedChangeListener实现了CompoundButton.OnCheckedChangeListener{}
changeToBlue.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton c, boolean b) {
        changeToBlue(background);
    }
});