private TextView createTitle(SwipeMenuItem item) { TextView tv = new TextView(getContext()); tv.setText(item.getTitle()); tv.setGravity(Gravity.CENTER); tv.setTextSize(item.getTitleSize()); tv.setTextColor(item.getTitleColor()); return tv; }
private ImageView createIcon(SwipeMenuItem item) { ImageView iv = new ImageView(getContext()); iv.setLayoutParams( new LayoutParams(Util.dpToPixel(getContext(), 25), Util.dpToPixel(getContext(), 25))); iv.setImageDrawable(item.getIcon()); return iv; }
private void addItem(SwipeMenuItem item, int id) { LayoutParams params = new LayoutParams(item.getWidth(), item.getHeight()); LinearLayout parent = new LinearLayout(getContext()); parent.setId(id); parent.setGravity(Gravity.CENTER); parent.setOrientation(LinearLayout.VERTICAL); parent.setLayoutParams(params); parent.setBackgroundDrawable(item.getBackground()); parent.setOnClickListener(this); addView(parent); if (item.getIcon() != null) { parent.addView(createIcon(item)); } if (!TextUtils.isEmpty(item.getTitle())) { parent.addView(createTitle(item)); } }
public void createMenu(SwipeMenu menu) { // Test Code SwipeMenuItem item = new SwipeMenuItem(mContext); item.setTitle("Item 1"); item.setBackground(new ColorDrawable(Color.GRAY)); item.setWidth(300); menu.addMenuItem(item); item = new SwipeMenuItem(mContext); item.setTitle("Item 2"); item.setBackground(new ColorDrawable(Color.RED)); item.setWidth(300); menu.addMenuItem(item); }
private ImageView createIcon(SwipeMenuItem item) { ImageView iv = new ImageView(getContext()); iv.setImageDrawable(item.getIcon()); return iv; }