prevent View Over Flow Action Items - Android User Interface

Android examples for User Interface:View

Description

prevent View Over Flow Action Items

Demo Code


//package com.java2s;
import java.lang.reflect.Field;

import android.content.Context;

import android.view.ViewConfiguration;

public class Main {
    /**//  w  w  w  .j  ava 2 s  . c  o m
     * @param context
     * 
     *            Disable the overflowMenuItem in the action bar , The three dot
     *            thingy is displayed NOTE: TO BE CALLED AT THE END OF THE
     *            ONCREATE
     */
    public static void preventOverFlowActionItems(Context context) {
        try {
            ViewConfiguration config = ViewConfiguration.get(context);
            Field menuKeyField = ViewConfiguration.class
                    .getDeclaredField("sHasPermanentMenuKey");
            if (menuKeyField != null) {
                menuKeyField.setAccessible(true);
                menuKeyField.setBoolean(config, true);
            }
        } catch (Exception ex) {
            // Ignore
        }
    }
}

Related Tutorials