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(???));
应用程序就像。
我们有不同的单选按钮,颜色作为选项,点击radioButton1
红色显示在多行文字区域,点击应用于背景,该颜色被应用在背景中进行整个活动。
现在问题是getResource()
中给出的代码应该是什么,以便从每个RadioButton
中选择颜色以将其应用于活动背景。
答案 0 :(得分:0)
将(getResources()。getResourceTypeName(???)更改为(getResources()。getColor(R.color.yourcolorname);
答案 1 :(得分:0)
getResources().getColor(R.color.yourcolorname);
从API 23中删除,改为使用:
ContextCompat.getColor(context, R.color.yourcolorname);