您的位置:首页 > 其它

使具有物理按键的手机能够显示Action Bar overflow

2015-06-23 20:59 357 查看
让overflow始终都显示:

public class XxxActivity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		...
	    
	    getOverflowMenu();
    }

	//force to show overflow menu in actionbar for android 4.4 below
	private void getOverflowMenu() {
	     try {
	        ViewConfiguration config = ViewConfiguration.get(this);
	        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
	        if(menuKeyField != null) {
	            menuKeyField.setAccessible(true);
	            menuKeyField.setBoolean(config, false);
	        }
	    } catch (Exception e) {
	        e.printStackTrace();
	    }
	}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: