所有,我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