所有,我hava滚动包含editText。scrollView.requestFocus()返回true,但它不起作用
一旦我点击editText,它将获得焦点并显示一个SoftInput。
在我看来,如果我单击空格,softinput hide,editText会失去焦点,并且scrollview会获得焦点。
所以我这样的代码:
scrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//call twice, once down, once up
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (activity.getCurrentFocus() != null && activity.getCurrentFocus().getWindowToken() != null) {
inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
scrollView.requestFocus();
activity.getCurrentFocus();
}
}
return false;
}
});
ScrollView
android:focusable="true"
android:focusableInTouchMode="true"
android:id="@+id/scrollView"
android:layout_below="@+id/topBar"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
但毕竟还是EDITTEXT重点(activity.getCurrentFocus()== EDITTEXT),有何意见?
以编程方式从编辑文本中删除焦点。 –
@MurtazaHussain我使用'activity.getCurrentFocus()。clearFocus();',仍然没有发生 – Ninja