我知道它不可能使用原生API。有周围的工作来实现的一种观点。
I know its not possible using the native API. Is there a work around to implement that kind of view.
推荐答案
在previously张贴的答案是确定的,一般来讲。但它基本上消除了溢出菜单的默认行为。之类的东西有多少图标可以显示在不同的屏幕尺寸,然后他们下车到溢出菜单时无法显示它们。通过这样做上述删除了很多重要的功能。
The previously posted answer is OK, generally speaking. But it basically removes the default behaviour of the Overflow menu. Things like how many icons can be displayed on different screen-sizes and then they dropped off into the overflow menu when they can't be displayed. By doing the above you remove a lot of important functionality.
有一个更好的方法是告诉溢出菜单中直接显示的图标。您可以通过添加以下code到你的活动做到这一点。
A better method would be to tell the overflow menu to display the icons directly. You can do this by adding the following code to your Activity.
@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);
m.invoke(menu, true);
}
catch(NoSuchMethodException e){
Log.e(TAG, "onMenuOpened", e);
}
catch(Exception e){
throw new RuntimeException(e);
}
}
}
return super.onMenuOpened(featureId, menu);
}
相关推荐
最新文章