ActionBar SearchView not fully expanding in landscape mode
10,636
Solution 1
Did you try something like that?
editView.setOnKeyListener(new OnKeyListener() {
private boolean extended = false;
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (!extended && event.getAction() == KeyEvent.ACTION_DOWN) {
extended = true;
LayoutParams lp = v.getLayoutParams();
lp.width = LayoutParams.MATCH_PARENT;
}
return false;
}
});
Solution 2
MenuItemCompat's SearchView has a property named maxWidth.
final MenuItem searchItem = menu.findItem(R.id.action_search);
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setMaxWidth(xxx);
use screen width instead of xxx offcourse
Author by
Collin Buchan
Updated on June 09, 2022Comments
-
Collin Buchan almost 2 years
When using the action bar search interface, the widget expands to occupy the full width of the screen in portrait mode, but stops short in landscape mode.
Is there a way to set the expansion layout params on the SearchView to fully fill the action bar when the user is typing a search?
See image:
Note: I'm not currently using ActionBar Sherlock
Edit: Here's what I did to get it to extend the full width.
searchView.setOnSearchClickListener(new OnClickListener() { private boolean extended = false; @Override public void onClick(View v) { if (!extended) { extended = true; LayoutParams lp = v.getLayoutParams(); lp.width = LayoutParams.MATCH_PARENT; } } });
-
Collin Buchan about 11 yearsClose. I wound up needing to use
setOnSearchClickListener()
since I'm not going for hardware key press search. -
Darklex over 9 yearsHow smooth is this to achieve in the ActionBar?
-
Anton Savenok about 8 yearssearchView.setMaxWidth( Integer.MAX_VALUE );