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;
}
}
});
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
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;
}
});
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