Example usage for android.view Menu getClass

List of usage examples for android.view Menu getClass

Introduction

In this page you can find the example usage for android.view Menu getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:co.carlosjimenez.android.currencyalerts.app.MenuTint.java

/**
 * Set the menu to show MenuItem icons in the overflow window.
 *
 * @param menu the menu to force icons to show
 *///from   ww  w  .  ja va  2  s  . c om
public static void forceMenuIcons(Menu menu) {
    try {
        Class<?> MenuBuilder = menu.getClass();
        Method setOptionalIconsVisible = MenuBuilder.getDeclaredMethod("setOptionalIconsVisible",
                boolean.class);
        if (!setOptionalIconsVisible.isAccessible()) {
            setOptionalIconsVisible.setAccessible(true);
        }
        setOptionalIconsVisible.invoke(menu, true);
    } catch (Exception ignored) {
    }
}

From source file:com.forrestguice.suntimeswidget.SuntimesUtils.java

/**
 * from http://stackoverflow.com/questions/18374183/how-to-show-icons-in-overflow-menu-in-actionbar
 */// w w w . ja v a 2s .c  om
public static void forceActionBarIcons(Menu menu) {
    if (menu != null) {
        if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
            try {
                Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
                m.setAccessible(true);
                m.invoke(menu, true);

            } catch (Exception e) {
                Log.e("SuntimesActivity", "failed to set show overflow icons", e);
            }
        }
    }
}

From source file:com.superyu.slidingmenu.SlidingMenu02.java

/**
 **??/* w  w  w . j a v  a 2 s .  c o  m*/
 **/

@Override
public boolean onMenuOpened(int featureId, Menu menu) {

    if (featureId == Window.FEATURE_ACTION_BAR && menu != null) {
        if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
            try {
                Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
                m.setAccessible(true);
                m.invoke(menu, true);
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    return super.onMenuOpened(featureId, menu);
}

From source file:tn.codeit.darna.MainActivity.java

@Override
public boolean onMenuOpened(int featureId, Menu menu) {
    if (featureId == Window.FEATURE_ACTION_BAR && menu != null) {
        if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
            try {
                Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
                m.setAccessible(true);//  w  w w. ja  v  a 2s. c  o  m
                m.invoke(menu, true);
            } catch (NoSuchMethodException e) {
                Log.e(null, "onMenuOpened", e);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    return super.onMenuOpened(featureId, menu);
}

From source file:im.vector.activity.MXCActionBarActivity.java

@Override
public boolean onMenuOpened(int featureId, Menu menu) {
    // display the menu icon with the text
    if (((featureId == Window.FEATURE_ACTION_BAR) || ((featureId == Window.FEATURE_OPTIONS_PANEL)))
            && menu != null) {/*from w w  w.j a  v  a 2  s.  c om*/
        if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
            try {
                Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
                m.setAccessible(true);
                m.invoke(menu, true);
            } catch (NoSuchMethodException e) {
                //Log.e(TAG, "onMenuOpened", e);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    return super.onMenuOpened(featureId, menu);
}

From source file:com.hellofyc.base.app.activity.BaseActivity.java

@Override
public boolean onMenuOpened(int featureId, Menu menu) {
    if (featureId == Window.FEATURE_ACTION_BAR && menu != null) {
        if ("com.android.internal.view.menu.MenuBuilder".equals(menu.getClass().getName())) {
            Reflect.on(menu).call("setOptionalIconsVisible", true);
        }//w  ww .jav a2s  .  co  m
    }
    return super.onMenuOpened(featureId, menu);
}

From source file:com.example.android.wifidirect.WiFiDirectActivity.java

@Override
public boolean onMenuOpened(int featureId, Menu menu) {
    if (featureId == Window.FEATURE_ACTION_BAR && menu != null) {
        if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
            try {
                Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
                m.setAccessible(true);//from   w  w w  .j a va2 s.c  o  m
                m.invoke(menu, true);
            } catch (Exception e) {
            }
        }
    }
    return super.onMenuOpened(featureId, menu);
}

From source file:net.gsantner.opoc.util.ContextUtils.java

/**
 * Try to make icons in Toolbar/ActionBars SubMenus visible
 * This may not work on some devices and it maybe won't work on future android updates
 *///from  w w  w  . jav  a2s .  c  o  m
public void setSubMenuIconsVisiblity(Menu menu, boolean visible) {
    if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
        try {
            @SuppressLint("PrivateApi")
            Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
            m.setAccessible(true);
            m.invoke(menu, visible);
        } catch (Exception ignored) {
            Log.d(getClass().getName(), "Error: 'setSubMenuIconsVisiblity' not supported on this device");
        }
    }
}

From source file:com.desno365.mods.Activities.MainActivity.java

@Override
public boolean onPrepareOptionsPanel(View view, Menu menu) {
    //add icons near menu items
    if (menu != null) {
        if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
            try {
                Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
                m.setAccessible(true);//from w ww  .  ja  v  a 2 s  . c o m
                m.invoke(menu, true);
            } catch (NoSuchMethodException e) {
                Log.e(TAG, "onMenuOpened", e);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    return super.onPrepareOptionsPanel(view, menu);
}

From source file:cn.edu.zafu.corepage.base.BaseActivity.java

@Override
public boolean onMenuOpened(int featureId, Menu menu) {
    if (featureId == Window.FEATURE_ACTION_BAR && menu != null) {
        if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
            try {
                Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
                m.setAccessible(true);/*from   www  . j av a2 s .c  o  m*/
                m.invoke(menu, true);
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    return super.onMenuOpened(featureId, menu);
}