Skip to content Skip to sidebar Skip to footer

How To Change Background Of Textview From Edittext Text Change?

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 TextVi

Solution 1:

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

TextWatchertextWatcher=newTextWatcher() {
@OverridepublicvoidonTextChanged(CharSequence s, int start, int before, int count) {}

@OverridepublicvoidbeforeTextChanged(CharSequence s, int start, int count, int after) {}

@OverridepublicvoidafterTextChanged(Editable s) {
    about_btn_Submit.setBackgroundColor(Color.parseColor("#9CCC65"));
}

};

editText.addTextChangedListener(textWatcher);

Solution 2:

Use a TextWatcher like this:

TextWatchertextWatcher=newTextWatcher() {
    @OverridepublicvoidonTextChanged(CharSequence s, int start, int before, int count) {}

    @OverridepublicvoidbeforeTextChanged(CharSequence s, int start, int count, int after) {}

    @OverridepublicvoidafterTextChanged(Editable s) {
        textView.setTextColor(Color.parseColor("#..."));
    }
};

editText.addTextChangedListener(textWatcher);

Note: You can also use textView.setTextColor(getResources().getColor(R.color.mycolor))

Solution 3:

Add TextChangedListener to your EditText as follows:

about_feedback.addTextChangedListener(new TextWatcher(){
    publicvoidafterTextChanged(Editable s) {
        // do what ever you want to TextView
    }
    publicvoidbeforeTextChanged(CharSequence s, int start, int count, int after){}
    publicvoidonTextChanged(CharSequence s, int start, int before, int count){}
}); 

Solution 4:

You can use TextWatcher

for eg:

EditText about_feedback= (EditText)findViewById(R.id.medittext);
about_feedback.addTextChangedListener(newTextWatcher() {

    @OverridepublicvoidafterTextChanged(Editable s) {
        // TODO Auto-generated method stub

    }

    @OverridepublicvoidbeforeTextChanged(CharSequence s, int start, int count, int after) {
        // TODO Auto-generated method stub

    }

    @OverridepublicvoidonTextChanged(CharSequence s, int start, int before, int count) {

        doSomething();



    } 

});

and you can use

about_btn_Submit.setTextColor(Color.parseColor("#FFFFFF"));

to change the color of the TextView

So,

in your code, do this in onTextChanged(), ie

publicvoidonTextChanged(CharSequence s, int start, int before, int count){
     about_btn_Submit.setTextColor(Color.parseColor("#FFFFFF"));
} 

Solution 5:

Thank you Guys for the answer @GuiLhe i Followed your answer,I wanted to change the background color of TextView so I wrote

about_btn_Submit.setBackgroundColor(Color.parseColor("#9CCC65"));

instead of

textView.setTextColor(Color.parseColor("#9CCC65"));

Thank you again

Post a Comment for "How To Change Background Of Textview From Edittext Text Change?"