0

我想处理折叠状态,但我无法处理 onActionExpandListener。我使用 actionbarsherlock,这是我的代码。我在哪里犯错?

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getSupportMenuInflater().inflate(R.menu.main, menu);
    menu.getItem(0).setVisible(aramaOnOff);
    menu.getItem(1).setVisible(filterOnOff);

    SearchView searchView = (SearchView)menu.findItem(R.id.imgBuyutec).getActionView();
    searchView.setOnQueryTextListener(this);

    searchViewItem = menu.findItem(R.id.imgBuyutec);
    searchViewItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            // TODO Auto-generated method stub
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {

            return true;
        }
    });

    return true;
}
4

1 回答 1

2

使用 appcompat-v7 , http://developer.android.com/guide/topics/ui/actionbar.html 然后使用下面的代码,

MenuItemCompat.setOnActionExpandListener(searchViewItem,new MenuItemCompat.OnActionExpandListener() {
    @Override
    public boolean onMenuItemActionExpand(MenuItem item) {
        //whatever
        return true;
    }

    @Override
    public boolean onMenuItemActionCollapse(MenuItem item) {
        //whatever
        return true;
    }
});
于 2013-12-04T09:46:52.720 回答