4

当您使用操作栏进入 searchview 模式时,由于某种原因,主页按钮更改为清单 android:icon drawable。有没有办法保持不变或将其改回 android:logo drawable?

这就是我正在做的事情:

@Override
public void onCreateOptionsMenu(final Menu menu, MenuInflater inflater) 
{
    getSherlockActivity().getSupportMenuInflater().inflate(R.menu.places_menu, menu);

    SearchManager searchManager = (SearchManager) getSherlockActivity().getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.item_menu_search).getActionView();

    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() 
    {
        public boolean onQueryTextChange(String newText) 
        {
            // this is your adapter that will be filtered
            mAdapter.getFilter().filter(newText);
            return true;
        }

        public boolean onQueryTextSubmit(String query) 
        {
            // this is your adapter that will be filtered
            mAdapter.getFilter().filter(query);
            return true;
        }
    };

    if (null != searchView )
    {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getSherlockActivity().getComponentName()));
        searchView.setIconifiedByDefault(false);  
        searchView.setOnQueryTextListener(queryTextListener);

        // CLOSE SEARCH WHEN SOFT KEYBOARD DISSMISSES
        searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean queryTextFocused) {
                if(!queryTextFocused) {
                    menu.findItem(R.id.item_menu_search).collapseActionView();
                    searchView.setQuery("", false);
                }
            }
        });
    }

    super.onCreateOptionsMenu(menu, inflater);
}
4

1 回答 1

4

setIcon()通过使用徽标调用似乎是可能的。

ActionBar actionBar = getActionBar();
actionBar.setLogo(R.drawable.ab_logo);
actionBar.setIcon(R.drawable.ab_logo);
于 2013-05-10T12:20:01.930 回答