我想在输入值是我的EditText字段来改变它的颜色 [英] I want my EditText field to change its color while entering values to it

查看:156
本文介绍了我想在输入值是我的EditText字段来改变它的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我虽然进入值到这个领域我想这会被我输入的值作为应用程序的运行emulator.But设计的XML文件中的编辑框的文本的颜色是灰色的,以被黑color.How做到这一点?例如说:

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:layout_width="300dip">
  </EditText>

下面的颜色为#C0C0C0(灰色),而进入我的仿真器的值到屏幕,数值应该会出现黑色的。

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

推荐答案

我不知道是否有办法做到这一点trought XML,但你可以d​​inamically改变你的编辑文本中的文本的颜色,使用焦点!

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!

您可以设置的 FocusChangeListener 的,这样当编辑文本的重点是,你可以使文本的黑色,当其不集中,它可以追溯到灰色。

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

}

}

这篇关于我想在输入值是我的EditText字段来改变它的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆