Situation:
I have a search widget on the appompat toolbar that allows me to create my own sentences through sqlitedatabase.
Problem:
I'm having trouble expanding the dropdown list to get the full screen width. In the best case, the width of the list is almost the width of the screen, with the exception of minor problems with stock / stock left and right. How to make a drop-down list the same width as the screen?
What I tried:
Search results list width
AutoCompleteText setPadding, setRight / setLeft, setDropDownHorizontalOffset, layout settings and installation width - match_parent.
menu / search.xml
<item android:id="@+id/search_restaurant" android:title="Search" android:icon="@drawable/search" android:orderInCategory="2" app:actionViewClass="android.support.v7.widget.SearchView" app:showAsAction="always"/>
Res / search_view_suggestions_list_item
<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="48dp" android:textAppearance="?android:attr/textAppearanceListItemSmall" android:background="@android:color/white" android:gravity="center_vertical" android:paddingLeft="16dp" android:paddingRight="16dp" android:minHeight="?android:attr/listPreferredItemHeightSmall"/>
activity / Activity.java
MenuItem searchItem = menu.findItem(R.id.search_restaurant); searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setQueryHint("Search Restaurant"); searchView.setOnQueryTextListener(this); searchView.setOnSuggestionListener(this); final AutoCompleteTextView searchAutoCompleteTextView = (AutoCompleteTextView) searchView .findViewById(R.id.search_src_text); searchAutoCompleteTextView.setThreshold(1); searchAutoCompleteTextView.setDropDownWidth(ViewGroup.LayoutParams.MATCH_PARENT); // Tried to change margins/padding here LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) searchAutoCompleteTextView.getLayoutParams(); params.setMargins(0, 0, 0, 0); searchAutoCompleteTextView.setLayoutParams(params); searchAutoCompleteTextView.setPadding(0, 0, 0, 0); searchAutoCompleteTextView.setDropDownHorizontalOffset(-100); searchAutoCompleteTextView.setPadding(0,0,0,0); searchAutoCompleteTextView.setLeft(0); final View dropDownSuggestions = searchView.findViewById(searchAutoCompleteTextView .getDropDownAnchor()); if (dropDownSuggestions != null) { dropDownSuggestions.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { int point[] = new int[2]; dropDownSuggestions.getLocationOnScreen(point); int dropDownPadding = point[0] + searchAutoCompleteTextView .getDropDownHorizontalOffset(); Rect screenSize = new Rect(); getWindowManager().getDefaultDisplay().getRectSize(screenSize); int screenWidth = screenSize.width(); searchAutoCompleteTextView.setDropDownWidth(screenWidth * 2); } }); }