set Menu Icon Enable - Android User Interface

Android examples for User Interface:Menu

Description

set Menu Icon Enable

Demo Code


//package com.java2s;
import android.util.Log;
import android.view.Menu;
import java.lang.reflect.Method;

public class Main {
    public static void setIconEnable(Menu menu, boolean enable) {
        try {/*from   www.j av a  2s  .  c  o m*/
            Class<?> clazz = Class
                    .forName("com.android.internal.view.menu.MenuBuilder");
            Method m = clazz.getDeclaredMethod("setOptionalIconsVisible",
                    boolean.class);
            m.setAccessible(true);
            m.invoke(menu, enable);
        } catch (Exception e) {
            Log.w(null, e);
        }
    }
}

Related Tutorials