Force the ActionBar to display the OverFlow button (three points)
About the three buttons at the rightmost of the ActionBar:
The official name should be overflow menu. devices above android 4.2.2 are displayed by default, but devices of android 4.1.2 are not displayed. It seems that android does not provide APIs for display, therefore, the mandatory display solution is found online (available for test ).
The key code is as follows:
private void getOverflowMenu() {ViewConfiguration viewConfig = ViewConfiguration.get(this);try {Field overflowMenuField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");if(null != overflowMenuField){overflowMenuField.setAccessible(true);overflowMenuField.setBoolean(viewConfig, false);}} catch (NoSuchFieldException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IllegalArgumentException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IllegalAccessException e) {// TODO Auto-generated catch blocke.printStackTrace();}}You can directly call the onCreate () method:
protected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_home_page);...//force to display overflow menu in action bargetOverflowMenu();}
The original author added that it would not be a problem to devices that are immediately applied to android4.4 or above: even if the overflowMenuField is null, the Code is also empty, so there is no impact.
I actually add the following version compatibility conditions when calling:
//force to display overflow menu in action bar when sdk version less than 21 if((Build.VERSION.SDK_INT >= 10) & (Build.VERSION.SDK_INT < 21)) {getOverflowMenu();}No problems found.
Finally, I would like to thank you for your selfless sharing.