Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionBar SearchView not fully expanding in landscape mode

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:

SearchView text field not using the full width in landscape mode

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

});
like image 238
Collin Buchan Avatar asked Apr 07 '13 21:04

Collin Buchan


2 Answers

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

like image 62
Wops Avatar answered Nov 01 '22 02:11

Wops


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

});
like image 20
cyanide Avatar answered Nov 01 '22 04:11

cyanide