Java 如何更改按钮上活动的背景色单击从单选按钮中选择颜色的位置
应用程序如下所示 我们有不同的单选按钮,以颜色作为选项,单击Java 如何更改按钮上活动的背景色单击从单选按钮中选择颜色的位置,java,android,Java,Android,应用程序如下所示 我们有不同的单选按钮,以颜色作为选项,单击radioButton1多行文本区域显示红色,单击应用于背景,该颜色应用于背景中的整个活动 现在的问题是,getResource()中给出的代码应该是什么,以便它从每个RadioButton中选择颜色,将其应用于活动背景。将(getResources().getResourceTypeName(?)更改为(getResources().getColor(R.color.yourcolorname);getResources().getC
radioButton1
多行文本区域显示红色,单击应用于背景,该颜色应用于背景中的整个活动
现在的问题是,getResource()
中给出的代码应该是什么,以便它从每个RadioButton
中选择颜色,将其应用于活动背景。将(getResources().getResourceTypeName(?)更改为(getResources().getColor(R.color.yourcolorname);getResources().getColor(R.color.yourcolorname);
从API 23中去除润滑脂,改用:
public void onClick(View v) {
View someView = findViewById(R.id.activity_success);
View root = someView.getRootView();
// what should be written here?? to display color
txtA.setBackgroundColor(getResources().getResourceTypeName(???));
你能提供更多的代码吗?你的问题不清楚,你的代码不足以理解你在尝试什么。
ContextCompat.getColor(context, R.color.yourcolorname);