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:org.symptomcheck.capstone.ui.MainActivityOld.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  .  co  m*/
                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.hzx.luoyechat.activity.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 method = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
                method.setAccessible(true);
                method.invoke(menu, true);
            } catch (Exception e) {
                e.printStackTrace();/*from   w w w  . j av a2  s  .  c  o  m*/
            }
        }
    }

    return super.onMenuOpened(Window.FEATURE_ACTION_BAR, menu);
}

From source file:com.aimfire.main.MainActivity.java

/**
 * Override Activity lifecycle method.//w  w w  .  ja v a  2  s  .  c  om
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_main, menu);

    /*
      * To show icon (instead of only text) in action bar overflow
      */
    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) {
            if (BuildConfig.DEBUG)
                Log.e(TAG, "onMenuOpened", e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.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 ww w  . jav a 2 s.  c o m*/
                m.invoke(menu, true);
            } catch (NoSuchMethodException e) {
                System.out.println("Could not display action icons in menu");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    return super.onMenuOpened(featureId, menu);
}

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

/**
 * from http://stackoverflow.com/questions/18374183/how-to-show-icons-in-overflow-menu-in-actionbar
 *//*from   www.j a  v  a  2 s.c  om*/
private 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.aimfire.gallery.GalleryActivity.java

/**
 * Override Activity lifecycle method./*  ww w . j a  v a2s. c om*/
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_gallery, menu);

    if (mViewPager != null) {
        shareUpdate(mViewPager.getCurrentItem());
    }

    /*
    * To show icon (instead of only text) in action bar overflow
    */
    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) {
            if (BuildConfig.DEBUG)
                if (VERBOSE)
                    Log.e(TAG, "onCreateOptionsMenu", e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return super.onCreateOptionsMenu(menu);
}