Hi All
I have a simple question - It is possible to add a menu item with an icon to a context menu ? I've searched this issue and all I found is that it is not possible, but in the Home screen of the Android device when I perform long-click a "add to home" context menu is being displayed, contains menu items with text and icon, so I figured there got to be a way of doing it.
I tried using the MenuItem.setIcon()
method but the icon is not disaplyed in the context menu, only the text.
Thanks!
Wherever you see icons, that's not a context menu. If it feels a bit like a context menu but has icons, that's probably an AlertDialog
with a custom ListAdapter
that uses rows with icons.
you need to expand your adapter
public class Menu_adapter extends BaseAdapter {
and the method
public View getView(int position, View convertView, ViewGroup parent) {
Menu_item menu_item = (Menu_item) this.getItem(position);
ViewHolder viewHolder;
if (convertView == null) {
convertView = lInflater.inflate(R.layout.item_left_elements, null);
viewHolder = new ViewHolder();
viewHolder.text = (TextView) convertView
.findViewById(R.id.tvDescr);
convertView.setTag(viewHolder);
convertView.setTag(R.id.tvDescr, viewHolder.text);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
ImageView imageView = (ImageView) convertView.findViewById(R.id.ivImage);
if (menu_item.get_Item_Use() == true ) {
imageView.setImageResource(R.drawable.ic_menu_arrow_icon_pressed);
} else {
imageView.setImageResource(R.drawable.ic_menu_arrow_icon);
}
viewHolder.text.setTag(position);
viewHolder.text.setText(res.getString(menu_item.get_Item_id()));
return convertView;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With