EDITTEXT不失去焦点焦点、EDITTEXT

由网友(我与你白首相礼)分享简介:在EDITTEXT不失去焦点在我的应用程序,当我点击了它,它有橙色边框的所有时间和黑线光标..我根据这个围绕EDITTEXT这是一个LinearLayout中所做的:Stop从在活动启动获得焦点的EditText所以它不会专注于应用程序的开始。the editText is not losing focus i...

在EDITTEXT不失去焦点在我的应用程序,当我点击了它,它有橙色边框的所有时间和黑线光标.. 我根据这个围绕EDITTEXT这是一个LinearLayout中所做的: Stop从在活动启动获得焦点的EditText 所以它不会专注于应用程序的开始。

the editText is not losing focus in my app when I click out of it, it has the orange border all time and that black line cursor.. I did this a LinearLayout according to this surrounding the editText: Stop EditText from gaining focus at Activity startup so it doesn't get focus on start of the app..

这是我的code:

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

不过,这似乎并没有被调用onFocusChange当我点击EDITTEXT以外的任何地方!

But, it doesn't seem to be calling the onFocusChange when I click anywhere outside the editText!

推荐答案

这很简单。你可以把下面的的LinearLayout或其他任何东西:

It's simple. You can put the following in LinearLayout or any other else:

android:focusableInTouchMode="true"
阅读全文

相关推荐

最新文章