简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM