【发布时间】:2012-02-12 12:31:04
【问题描述】:
在赋予 EditText 小部件自定义颜色后,如何重置其默认背景?
【问题讨论】:
标签: android colors background android-edittext reset
在赋予 EditText 小部件自定义颜色后,如何重置其默认背景?
【问题讨论】:
标签: android colors background android-edittext reset
我必须为我编写的应用程序这样做。在此示例中,我检查 EditText 是否为空,如果为空,则创建一个 TextWatcher。看看吧:
// highlight any unfilled boxes
final EditText text = (EditText) activity.findViewById(id);
String data = text.getText().toString();
if (data.length() == 0) //
{
final Drawable oldBackground = activity.findViewById(id).getBackground();
text.setBackgroundColor(Color.YELLOW);
text.addTextChangedListener(new TextWatcher() //
{
@Override
public void afterTextChanged(Editable s) //
{
text.setBackgroundDrawable(oldBackground);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
{ }
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{ }
});
}
希望这会有所帮助!
【讨论】: