Search code examples
androidsearchandroid-actionbarsearchview

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

});

Solution

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