如何从EditText文本更改更改TextView的背景? [英] How to change background of TextView From EditText Text Change?

查看:100
本文介绍了如何从EditText文本更改更改TextView的背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Fragment类,当我在编辑Text上更改文本时,我想在其中更改Text View的颜色.在EditText中更改文本时,可以使用哪些方法来更改TextView的背景颜色.我的代码如下:

I am using Fragment class in which I want to change the color of Text View When text is changed on my edit Text. What are the possible ways to change the background color of TextView When Text is Changed in EditText . My code looks like this :

public class Fragment_AboutUs extends android.app.Fragment {
    TextView about_btn_call_customer;
    TextView about_btn_Submit;
    EditText about_feedback;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.layout_fragment_about_us, container, false);
        //reference section
        about_btn_call_customer= (TextView) rootView.findViewById(R.id.about_btn_call_customer);
        about_btn_Submit=(TextView)rootView.findViewById(R.id.about_btn_Submit);
        about_feedback=(EditText)rootView.findViewById(R.id.about_feedback);
        return rootView;
    }
}

任何帮助将不胜感激.

推荐答案

我的解决方案是对@GuiihE代码进行一些修改. 尝试此解决方案,它将根据您的要求解决:

My solution is a little modification of @GuiihE codes. Try this solution,it would work out as per your requirements:

TextWatcher textWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

@Override
public void afterTextChanged(Editable s) {
    about_btn_Submit.setBackgroundColor(Color.parseColor("#9CCC65"));
}

};

editText.addTextChangedListener(textWatcher);

editText.addTextChangedListener(textWatcher);

这篇关于如何从EditText文本更改更改TextView的背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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