Forces actionbar items to be in actionbar otherwise phones might show it in bottom bar spinner instead of actionbar - Android User Interface

Android examples for User Interface:ActionBar

Description

Forces actionbar items to be in actionbar otherwise phones might show it in bottom bar spinner instead of actionbar

Demo Code


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

import android.app.Activity;
import android.view.ViewConfiguration;

public class Main {
    /**/*from w  w w .  j a va2  s .co m*/
     * Forces actionbar items to be in actionbar
     *  otherwise phones might show it in bottom bar spinner
     *  instead of actionbar
     * @param the activity, should be 'this'
     */
    public static void forceShowActionBar(Activity act) {
        try {
            ViewConfiguration config = ViewConfiguration.get(act);
            Field menuKeyField = ViewConfiguration.class
                    .getDeclaredField("sHasPermanentMenuKey");
            if (menuKeyField != null) {
                menuKeyField.setAccessible(true);
                menuKeyField.setBoolean(config, false);
            }
        } catch (Exception ex) {
            // Ignore
        }
    }
}

Related Tutorials