Leo Droidcoder Leo Droidcoder - 1 month ago 10
Android Question

How to highlight/focus two EditTexts in Android?

I have two EditTexts in an activity. I am trying to implement it so that when one EditText is focused, the second one looks like it is focused too (the underline must be bold as it is when EditText is focused).

I am trying to change underline like this when focus changes:

editText1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
// here editText2 must have not state
} else {
// here editText2 must have not state
}
}
});


But how can I make the underline bold on another text without it actually receiving focus?

Answer

Try this

editText1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
                  if (!hasFocus) {
                       editText2.setTypeface(Typeface.NORMAL);

                  } else {
                       editText2.setTypeface(Typeface.DEFAULT_BOLD); 
                  }
              }
          });