The xml is as follow.
I want to implement the function like this: when I click the edittext, the soft input show.
when I scroll(not scroll to OnScrollListener.SCROLL_STATE_IDLE
state) the listview the soft input hide.
I use the android:windowSoftInputMode="adjustResize"
.
When a BottomNavigationView will show and hide on scrolling it will look much more professional and practical. You have also seen in LinkedIn, that how it’s BottomNavigationView shows and hide on scrolling. Do you also not want to implement it in BottomNavigationView of your own app.
In case the heights of the items are different and not set, move on to another method in this article. This example app contains a ListView with 100 items and a floating button. When the user presses the floating button, the view will scroll to a random item (you can replace it with a constant number if you want to).
Define an interface to hide the soft keyboard. In a native Android project, create a class to hide the keyboard and register the dependency for the same. Hide the soft keyboard using HideSoftInputFromWindow method , and clear the focus using ClearFocus method.
Trigger the ScrollStateChanged method to hide the keyboard. In the event call back, call the HideKeyBoard method using DependencyService when the ScrollState is not Idle. The ultimate Xamarin UI toolkit to boost your development speed.
Detect your scroll using this link,
it implements onScrollListener
, which you will set to your ListView
and in its onScrollStateChanged()
you will put this code in your -
setOnScrollListener(new OnScrollListener(){
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState !=0){
InputMethodManager inputMethodManager = (InputMethodManager)
getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
}
});
InputMethodManager inputMethodManager = (InputMethodManager)
getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
gives a bug in AS... Use this instead inside onScrollStateChange
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(absListView.getApplicationWindowToken(), 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With