setBackgroundColor是一个(int)?

时间:2017-11-18 20:07:48

标签: java android

有人可以帮我这个: 我把这段代码: linear0.setBackgroundColor( “0xFF” 组成.concat(input.getText()的toString())); 并且发生错误,表示View类型中的setBackgroundColor(int)不适用于参数(String)! 如何在edittext中将背景颜色设置为用户输入的值?

1 个答案:

答案 0 :(得分:1)

要从EditText获取值,您必须初始化并设置EditText:

EditText text = findViewById(R.id.editText)

然后从EditText中获取值:

String value = text.getText().toString();

然后将字符串解析为整数并设置背景颜色

int color = Integer.parseInt(value);
back_button.setBackgroundColor(color);