简体   繁体   中英

Remove overscroll effect on AutoCompleteTextView popup (Android Studio / Java / XML)

I'm currently trying to remove the overscroll effect on the popup of the AutoCompleteTextView, but everything I have tried yet, did not work. My AutoCompleteTextView uses an ArrayAdapter to store the keywords and a simple layout to display its items.

Setup of the ArrayAdapter:

    String[] keywords = new String[] { "test", "test2", "test3", "test4", "test5" };
    ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, keywords);
    ((AutoCompleteTextView)findViewById(R.id.actvSearch)).setAdapter(adapter);

To remove the effect I have tried to set the overScrollMode of the AutoCompleteTextView, but this does not seem to have any effect on the popup.

Is there any way to set the overScrollMode of the popup to "never" or any simple (not overriding the ArrayAdapter class) way to limit the amount of items which are shown at once, so that the overscroll effect does not even appear?

Thanks, Ypselon.

I found a solution to remove the scroll effect by overriding the getView() method. so in the getView() method add this line to the parent:

parent.setOverScrollMode(View.OVER_SCROLL_NEVER);

Your Adapter should looks like below

 String[] keywords = new String[] { "test", "test2", "test3", "test4", "test5" };
 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, keywords){
            @NonNull
            @Override
            public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
                parent.setOverScrollMode(View.OVER_SCROLL_NEVER);
                return super.getView(position, convertView, parent);
            }
        };
 ((AutoCompleteTextView)findViewById(R.id.actvSearch)).setAdapter(adapter);

Note : the parent.setOverScrollMode(View.OVER_SCROLL_NEVER); is called every time you scroll the list

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM