[英]how to change the background color of activity on button click where color is picked from radio button
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(???));
the application is like. 该应用程序就像。
We have different radio button with colors as options and on click of radioButton1
red color is displayed in multi line text area, and on clicking on Apply to Background , that color is applied to whole activity in background. 我们有不同的单选按钮,带有颜色作为选项,单击
radioButton1
,多行文本区域显示红色,并且单击“ 应用于背景”时 ,该颜色将应用于背景中的整个活动。
Now the question is what should be the code given in getResource()
so that it picks the color from every RadioButton
to apply it to the activity background. 现在的问题是,
getResource()
给出的代码应该是什么,以便它从每个RadioButton
选择颜色以将其应用于活动背景。
将(getResources()。getResourceTypeName(???)更改为(getResources()。getColor(R.color.yourcolorname);
getResources().getColor(R.color.yourcolorname);
从API 23中摘录,请改用:
ContextCompat.getColor(context, R.color.yourcolorname);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.