(求助)editText焦点监听不起作用 在布局文件中增加父控件属性android:focusable="true"试一下呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在布局文件中加了android:focusable="true"也不管用,还是没有跑到onFocusChange。我的EDITTEXT是一个搜索输入框,做一个百度地图的应用,输入完后想实现点击其他地方隐藏输入法 EditText输入完成以后,不用点击按钮吗?譬如“提交”、“搜索”什么的。 我测试了一下<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/linear" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:focusable="true" android:focusableInTouchMode="true"> <EditText android:id="@+id/input" android:layout_width="match_parent" android:layout_height="wrap_content"/></LinearLayout>public class MainActivity extends Activity { private EditText _input; private LinearLayout _linear; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); _input = (EditText)findViewById(R.id.input); /*_input.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View arg0, boolean arg1) { Toast.makeText(getApplicationContext(), "EditText焦点改变", Toast.LENGTH_SHORT).show(); } });*/ _linear = (LinearLayout)findViewById(R.id.linear); _linear.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent arg1) { _linear.requestFocus(); Toast.makeText(getApplicationContext(), "Layout获取焦点", Toast.LENGTH_SHORT).show(); InputMethodManager inputManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); if (inputManager.isActive()) { inputManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); }这样可以实现。 我测试了一下<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/linear" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:focusable="true" android:focusableInTouchMode="true"> <EditText android:id="@+id/input" android:layout_width="match_parent" android:layout_height="wrap_content"/></LinearLayout>public class MainActivity extends Activity { private EditText _input; private LinearLayout _linear; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); _input = (EditText)findViewById(R.id.input); /*_input.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View arg0, boolean arg1) { Toast.makeText(getApplicationContext(), "EditText焦点改变", Toast.LENGTH_SHORT).show(); } });*/ _linear = (LinearLayout)findViewById(R.id.linear); _linear.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent arg1) { _linear.requestFocus(); Toast.makeText(getApplicationContext(), "Layout获取焦点", Toast.LENGTH_SHORT).show(); InputMethodManager inputManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); if (inputManager.isActive()) { inputManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); }这样可以实现。谢谢,按照类似的方法改了 android 图片资源被放大 谁知道58同城android客户端用的什么界面库? 源码里面:屏幕锁定提示音的相关实现代码是在哪里实现的啊? MediaPlayer同步播放问题 新建的android项目咋是这样的,求高手回答。 android 问题求救 Android下如何获得刚刚输入的字符是那个字符? 关于Android系统时间监听的问题 求Android画册制作思路! 服务器的数据和软件连接 安卓开发,如何读取手机文件 关于SQLite 的DAO层设计问题 ,求大神指点下!
我的EDITTEXT是一个搜索输入框,做一个百度地图的应用,输入完后想实现点击其他地方隐藏输入法
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"> <EditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"/></LinearLayout>
public class MainActivity extends Activity {
private EditText _input;
private LinearLayout _linear;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_input = (EditText)findViewById(R.id.input);
/*_input.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View arg0, boolean arg1) {
Toast.makeText(getApplicationContext(), "EditText焦点改变",
Toast.LENGTH_SHORT).show();
}
});*/
_linear = (LinearLayout)findViewById(R.id.linear);
_linear.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
_linear.requestFocus();
Toast.makeText(getApplicationContext(), "Layout获取焦点",
Toast.LENGTH_SHORT).show();
InputMethodManager inputManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputManager.isActive()) {
inputManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
}
return false;
}
});
}
这样可以实现。
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"> <EditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"/></LinearLayout>
public class MainActivity extends Activity {
private EditText _input;
private LinearLayout _linear;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_input = (EditText)findViewById(R.id.input);
/*_input.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View arg0, boolean arg1) {
Toast.makeText(getApplicationContext(), "EditText焦点改变",
Toast.LENGTH_SHORT).show();
}
});*/
_linear = (LinearLayout)findViewById(R.id.linear);
_linear.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
_linear.requestFocus();
Toast.makeText(getApplicationContext(), "Layout获取焦点",
Toast.LENGTH_SHORT).show();
InputMethodManager inputManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputManager.isActive()) {
inputManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
}
return false;
}
});
}
这样可以实现。谢谢,按照类似的方法改了