开发者

I want my EditText field to change its color while entering values to it

开发者 https://www.devze.com 2023-03-27 08:04 出处:网络
I have to design an xml file in which the color of the text on the Editfield is grey as the application runs on the emulator.But while entering the values into that field I want the values which will

I have to design an xml file in which the color of the text on the Editfield is grey as the application runs on the emulator.But while entering the values into that field I want the values which will be entered by me,to be black in color.How to do this? Say for Example:

   <EditText android:text="minuten" 
            android:textColor="#C0C0C0"
            android:layout_height="wrap_content" 
            android:id="@+id/editText2" 
            android:layou开发者_如何学编程t_width="300dip">
  </EditText>

Here the color is #C0C0C0(grey),while entering the values on my emulator into the screen,the values should appear black in color.


I don't know if there is a way to do that trought xml, but you can change the color of the text inside your edit text dinamically, using the focus!

You can set a FocusChangeListener, that way when the edit text is focused, you can make the text black, when its not focused, it goes back to gray.

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.EditText;

public class Q7035767 extends Activity {
/** Called when the activity is first created. */

EditText et1;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    et1 = (EditText) findViewById(R.id.editText1);        


    et1.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus)  
                  et1.setTextColor(Color.BLACK);           
              else
                  et1.setTextColor(Color.GRAY);             
        }
    });

}

}


i think android:textColor will solve your problem

reference:http://developer.android.com/reference/android/widget/TextView.html

0

精彩评论

暂无评论...
验证码 换一张
取 消