重置的EditText BACKGROUNDCOLOR默认
我有一个EditText
,然后:重置的EditText BACKGROUNDCOLOR默认
private void RegEmail_TextChanged(object sender, Android.Text.TextChangedEventArgs e)
{
var orginalDrawable = RegEmail.Background;
if (RegEmail.Text.Contains("@") && (RegEmail.Text.Contains(".")))
{
RegEmailB = true;
RegEmail.SetBackgroundColor(Color.Green);
}
else
{
RegEmailB = false;
RegEmail.SetBackgroundColor(Color.Red);
}
}
基本上,我需要把它设回默认状态..但大部分我发现东西都在java或不存在。
您必须保存TextChanged
外EditText
的原始状态。这是一个完整的工作解决方案。
private EditText RegEmail;
private Drawable _orginalDrawable;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
RegEmail = FindViewById<EditText>(Resource.Id.myEdt);
_orginalDrawable = RegEmail.Background;
RegEmail.TextChanged += (sender, e) =>
{
if (RegEmail.Text.Contains("@") && (RegEmail.Text.Contains(".")))
{
RegEmail.Background = _orginalDrawable;
}
else
{
RegEmail.SetBackgroundColor(Color.Red);
}
};
}
感谢您的帮助芽:)任何人看我已经采取了他的代码和它的工作在我的问题。 –
设定要设置回在以后的时间尝试之前,你可以得到的颜色,
var buttonBackground = RegEmail.Background;
Color backgroundColor;
if(buttonBackground is ColorDrawable)
{
backgroundColor = (buttonBackground as ColorDrawable).Color;
//You now have a background color.
}
if(backgroundColor != null)
RegEmail.SetBackgroundColor(backgroundColor);
Color.Empty;不存在 –
你可以将它设置为任何颜色:),你不指望它是,就像colour.white –
我需要它在设置红色之前已经设置的颜色。 –
我更新了它,因为我想告诉你它不起作用。 –
我无法在评论中粘贴所有代码 –
有一个很好的计算器实践,你不应该用正确的答案编辑你的问题。请回复原来的答案。 – jzeferino