android - editText 没有失去焦点

标签 android android-edittext

当我点击它时,editText 在我的应用程序中没有失去焦点,它一直有橙色边框和那个黑线光标.. 我根据editText周围的这个做了一个LinearLayout: Stop EditText from gaining focus at Activity startup 所以它不会专注于应用程序的启动..

这是我的代码:

final EditText et = (EditText)findViewById(R.id.EditText01);

final InputMethodManager imm = (InputMethodManager) getSystemService(
   INPUT_METHOD_SERVICE);

et.setOnClickListener(new View.OnClickListener() {
   public void onClick(View v) {
      imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);
   }
});

et.setOnFocusChangeListener(new View.OnFocusChangeListener() {
   public void onFocusChange(View v, boolean hasfocus) {
      if(hasfocus) {
         imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);
      } else {
         imm.hideSoftInputFromWindow(et.getWindowToken(), 0);
      }
   }
});

但是,当我点击editText之外的任何地方时,它似乎并没有调用onFocusChange!

最佳答案

这很简单。您可以将以下内容放入 LinearLayout 或其他任何内容中:

android:focusableInTouchMode="true"

关于android - editText 没有失去焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4489439/

相关文章:

javascript - 如何使用angularjs处理多页面网站?

android - EditText 导致 Activity 泄漏。目前的 stackoverflow 答案没有帮助

android - Android 中 ScrollView 中的 EditText

android - 如何在 Android 中使用正则表达式

Android 应用内购买用户标识

安卓用户界面 : what kind of layout options are mutually exclusive?

android - Android 应用程序的图像大小

android - EditText textCapSentences 不起作用

android - 没有文本时,光标在 EditText 中不可见

android - ListView 与 OnItemClickListener