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;
}
}
Any kind of help would be appreciated.
Add
TextChangedListener
to yourEditText
as follows:Use a TextWatcher like this:
Note: You can also use
textView.setTextColor(getResources().getColor(R.color.mycolor))
My solution is a little modification of @GuiihE codes. Try this solution,it would work out as per your requirements:
};
editText.addTextChangedListener(textWatcher);
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
You can use
TextWatcher
for eg:
and you can use
to change the color of the
TextView
So,
in your code, do this in
onTextChanged()
, ie