示例#1
0
 private void createMenu(SwipeMenu menu) {
   SwipeMenuItem item1 = new SwipeMenuItem(getActivity().getApplicationContext());
   item1.setBackground(new ColorDrawable(Color.rgb(0xE5, 0x18, 0x5E)));
   item1.setWidth(dp2px(90));
   item1.setIcon(R.drawable.ic_action_share);
   menu.addMenuItem(item1);
   SwipeMenuItem item2 = new SwipeMenuItem(getActivity().getApplicationContext());
   item2.setBackground(new ColorDrawable(Color.rgb(0xE5, 0xE0, 0x3F)));
   item2.setWidth(dp2px(90));
   item2.setIcon(R.drawable.ic_action_important);
   menu.addMenuItem(item2);
 }
  private void createModifiableMenu(SwipeMenu menu) {
    final SwipeMenuItem topItem = new SwipeMenuItem(getActivity().getApplicationContext());
    topItem.setBackground(new ColorDrawable(0xffc7c7cc));
    topItem.setTitle(getString(R.string.xiu_top));
    topItem.setTitleColor(0xff313131);
    topItem.setTitleSize(getResources().getDimensionPixelSize(R.dimen.swipe_menu_item_text_size));
    topItem.setTypedValue(TypedValue.COMPLEX_UNIT_PX);
    topItem.setWidth(getResources().getDimensionPixelSize(R.dimen.swipe_menu_item_width));
    menu.addMenuItem(topItem);

    final SwipeMenuItem deleteItem = new SwipeMenuItem(getActivity().getApplicationContext());
    deleteItem.setBackground(new ColorDrawable(0xffff3b30));
    deleteItem.setTitle(getString(R.string.delete_message));
    deleteItem.setTitleColor(0xffffffff);
    deleteItem.setTitleSize(
        getResources().getDimensionPixelSize(R.dimen.swipe_menu_item_text_size));
    deleteItem.setTypedValue(TypedValue.COMPLEX_UNIT_PX);
    deleteItem.setWidth(getResources().getDimensionPixelSize(R.dimen.swipe_menu_item_width));
    menu.addMenuItem(deleteItem);
  }
 @Override
 public void create(SwipeMenu menu) {
   switch (menu.getViewType()) {
     case XiuInfo.TYPE_DEFAULT:
       break;
     case XiuInfo.TYPE_MODIFIABLE:
       createModifiableMenu(menu);
       break;
     case 2:
       createModifiableTopMenu(menu);
       break;
   }
 }
 @Override
 public boolean onMenuItemClick(final int position, final SwipeMenu menu, final int index) {
   switch (menu.getViewType()) {
     case XiuInfo.TYPE_DEFAULT:
       break;
     case XiuInfo.TYPE_MODIFIABLE:
       modifiableMenuClick(position, index);
       break;
     case 2:
       topMenuClick(position);
       break;
   }
   return false;
 }