1

每个人!我正在使用SlidingMenu带有ActionBarSherlock. 当我设置uiOptionsto 时splitActionBarWhenNarrowActionItemsfrombottombar不是 clicable。此问题仅在 android v2.3 及更低版本上重现。我认为SlidingMenu拦截触摸ActionItem在底部栏中。如果我触摸ActionItem并滑动SlidingMenuActionItem就会被选中。我尝试添加actionItem为被忽略SlidingMenu,但它没有帮助:(

这是我的代码示例:

public class ExampleFragment extends BaseFragment{

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_positions, null);
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    ((BaseActivity)getActivity()).getSlidingMenu().clearIgnoredViews();

    final SubMenu deal = menu.addSubMenu(R.string.deal).setIcon(R.drawable.ic_actionbar_deal);
    deal.add(1, R.string.close_position, 0, R.string.close_position);
    deal.add(1, R.string.open_position, 0, R.string.open_position);
    final MenuItem dealItem = deal.getItem();
    dealItem.setIcon(R.drawable.ic_actionbar_deal);
    dealItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    final SubMenu edit = menu.addSubMenu(R.string.change).setIcon(R.drawable.ic_actionbar_edit);
    edit.add(2, R.string.change_limitation, 0, R.string.change_limitation);
    final MenuItem editItem = edit.getItem();
    editItem.setIcon(R.drawable.ic_actionbar_edit);
    editItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    if(DataContext.getInstance().getOpenPositions().size() == 0){
        menu.findItem(R.string.close_position).setEnabled(false);
        menu.findItem(R.string.change_limitation).setEnabled(false);
    }

    menu.add(0, R.string.reports, 0, R.string.reports).setIcon(R.drawable.ic_actionbar_report_stub).
            setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    ignoreMenuItems(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()){
        case R.string.open_position:
            Log.v(TAG, "onOptionsItemSelected open_position");
            break;
        case R.string.close_position:
            Log.v(TAG, "onOptionsItemSelected close_position");
            break;
        case R.string.change_limitation:
            Log.v(TAG, "onOptionsItemSelected change_limitation");
            break;
        case R.string.reports:
            Log.v(TAG, "onOptionsItemSelected reports");
            break;
    }
    return true;
}

public void ignoreMenuItems(Menu menu){
    for(int i = 0; i < menu.size(); i++){
        final MenuItem item = menu.getItem(i);
        View view = getActivity().getLayoutInflater().inflate(R.layout.layout_action_view, null);
        ((ImageView) view.findViewById(R.id.action_view_image)).setImageDrawable(item.getIcon());
        if(item.getSubMenu() != null){
            item.getSubMenu().setHeaderView(view);
        } else {
            item.setActionView(view);
            view.setLongClickable(true);
            view.setOnClickListener( new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onOptionsItemSelected(item);
                }
            });
            view.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View view) {
                    Toast.makeText(getActivity(), item.getTitle(), Toast.LENGTH_SHORT).show();
                    return true;
                }
            });
        }
        ((BaseActivity)getActivity()).getSlidingMenu().addIgnoredView(view);
    }
}

有任何想法吗?

4

0 回答 0