2011-08-11 12 views
2

私は編集テキストフィールドを持っています。私はそれが透明な背景を持ってほしい。しかし、ユーザーがそれを編集しようとすると、背景が白で、テキストの色が黒でなければなりません。そして、彼が編集テキストの編集を完了し、次のコントロールに移動して他の値を入力すると、背景が再び透明になります。これがアンドロイドでどのように可能か教えてください。助けと時間をいただきありがとうございます。編集モードのときに編集テキストの背景を制御する方法。アンドロイド用?

答えて

3
EditText editText = (EditText)findViewById(R.id.edit1); 
editText.setOnFocusChangeListener(new OnFocusChangeListener() { 
    @Override 
    public void onFocusChange(View v, boolean hasFocus) { 
     EditText editText = (EditText)findViewById(R.id.edit1); 
     editText.setBackgroundColor(hasFocus ? Color.WHITE : Color.TRANSPARENT); 
     editText.setTextColor(hasFocus ? Color.BLACK : Color.GRAY); 
    } 
}); 
1

onFocusChabgeListener()を以下のように実装します。

textView.setOnFocusChangeListener(new OnFocusChangeListener(){ 

if(textView.hasFocuss){ 
//set textColor and background color 
} 
else 
{ 
//reset it 
} 

}); 
関連する問題