SearchView Suggestion - Layout Width: match_parent

How to display Searcha hints that use the entire width of the screen using appcompat-v7:21 ?

I use android.support.v7.widget.SearchView in the code and menu resource. The new toolbar widget has searchViewStyle , but I could not find a parameter for displaying sentences over the entire width (match_parent).

Example
(source: netdna-cdn.com )

+6
source share
1 answer

you can do it like this: (this is on DropDownAnchor)

 @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_search, menu); MenuItem searchItem = menu.findItem(R.id.action_search_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); int searchEditTextId = R.id.search_src_text; final AutoCompleteTextView searchEditText = (AutoCompleteTextView) searchView.findViewById(searchEditTextId); final View dropDownAnchor = searchView.findViewById(searchEditText.getDropDownAnchor()); if (dropDownAnchor != null) { dropDownAnchor.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) { // screen width int screenWidthPixel = ActivitySearchUni.this.getResources().getDisplayMetrics().widthPixels; searchEditText.setDropDownWidth(screenWidthPixel); } }); } return true; } 
+4
source

Source: https://habr.com/ru/post/980999/


All Articles