简体   繁体   English

如何在Android中突出显示/聚焦两个EditText?

[英]How to highlight/focus two EditTexts in Android?

I have two EditTexts in an activity. 我在一个活动中有两个EditTexts。 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). 我正在尝试实现它,以便当一个EditText聚焦时,第二个看起来也聚焦(下划线必须是EditText聚焦时的粗体)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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