【发布时间】:2018-03-26 08:21:49
【问题描述】:
我想在运行时更改可绘制资源文件。
.java 文件代码
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button)findViewById(R.id.button);
edt1 = (EditText)findViewById(R.id.name);
edt2 = (EditText)findViewById(R.id.password);
str_name = edt1.getText().toString() ;
str_password = edt2.getText().toString();
if (str_name == 0 && str_password == 0) {
btn.setBackgroundResource(R.drawable.image);
}
else {
btn.setBackgroundResource(R.drawable.on_button_click);
}
问题是它应用了if 条件,但是当我在EditText 中输入一些文本时,资源文件并没有改变。
EditText(s) 在TextInputLayout 之下。
【问题讨论】:
-
你不能使用 == 比较字符串使用 .equals() 方法
-
而且您甚至无法将对象与整数进行比较,就像您目前正在尝试做的那样。
-
你可以查看我的答案。
标签: android android-textinputlayout