SearchView taking all the space in the new ActionBarCompat

前端 未结 3 596
广开言路
广开言路 2020-12-09 04:29

I switched from ActionBarSherlock to ActionBarCompat (support library v7). After some adjustments, almost everything is working fine by now.

But I\'m in trouble with

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 05:11

    This is definitely a bug about Android but a workaround can be including SearchView programmatically like this:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());
        searchView.setIconifiedByDefault(false);
        getActionBar().setCustomView(searchView);
        getActionBar().setDisplayShowCustomEnabled(true);
    }
    

    You can also use a layout XML to define SearchView properties. However "iconifiedByDefault" in XML tends to be ineffective in my experience. (This may my bad though)

    Thanks for creating an issue about this. Here's the URL to the related bug report: https://code.google.com/p/android/issues/detail?id=58251

    Despite what is mentioned in the bug report, my experience was the same with both ActionBarSherlock and ActionBarCompat. So I expect that ActionBarSherlock users are also affected.

提交回复
热议问题