2016-06-28 6 views
1

をデフォルトにリセットし、私はその後、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であるか、存在しません。

+0

私はそれがあなたの作品を見せたいと思っていたので、私はそれを更新しました。 –

+0

コメントにすべてのコードを貼り付けることはできません –

+0

正しい答えで質問を編集しないでください。元の回答に戻してください。 – jzeferino

答えて

1

を色を得ることができます。ここに完全に動作する完全なソリューションがあります。

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); 
     } 
    }; 
} 
+0

助けを借りてありがとう:)誰も私は自分のコードを取って、 –

0

あなたがしようと後で戻ってそれを設定し、それを設定する前に、あなたはあなたがTextChangedEditTextの元の状態を保存する必要があり、

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); 
+0

Color.Empty; –

+0

あなたはどんな色にでも設定できます:) colour.white –

+0

のように、あなたはそれが期待できません。すでに赤色が設定される前に色の設定が必要です。 –

関連する問題