简体   繁体   English

Android拆分操作栏顶部和底部带有操作项?

[英]Android Split Action Bar with Action Items on the top and bottom?

Is there a way to specify some action items to the top part of the Split Action Bar while the others go to the bottom? 有没有一种方法可以在“拆分操作栏”的顶部指定一些操作项,而其他操作则在底部? Or is it all or nothing, whereby all the action items go to the bottom part of the split only? 还是全部还是什么都没有,从而所有操作项都只进入拆分的底部?

在此处输入图片说明

This is currently not possible. 目前这是不可能的。

See the response directly from Android developers Reto Meier and Roman Nurik during the Android Developer Office Hours: http://youtu.be/pBmRCBP56-Q?t=55m50s 直接从Android开发的Reto Meier和罗马Nurik查看在Android开发者办公时间响应: http://youtu.be/pBmRCBP56-Q?t=55m50s

To solve this I used a custom view as my action bar: 为了解决这个问题,我使用自定义视图作为操作栏:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

    View view = View.inflate(getApplicationContext(), R.layout.actionbar,
            null);
    actionBar.setCustomView(view);

}

and then for the bottom bar I inflated my menu view or whatever you want to appear at bottom: 然后对于底部的栏,我放大了菜单视图或您想在底部显示的内容:

 @Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.browser_main, menu);
    RelativeLayout relativeLayout = (RelativeLayout) menu.findItem(
            R.id.layout_item).getActionView();

    View inflatedView = getLayoutInflater().inflate(
            R.layout.media_bottombar, null);

    relativeLayout.addView(inflatedView);

    return true;
}

In the Android Manifest, I also include (android:uiOptions="splitActionBarWhenNarrow") like this: 在Android清单中,我还包含(android:uiOptions =“ splitActionBarWhenNarrow”),如下所示:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:uiOptions="splitActionBarWhenNarrow" > ....

我通过使用CustomView并向该视图添加应该显示在顶部的菜单项解决了这个问题。

If this option is activated, Android has the option to split the action bar. 如果激活此选项,则Android可以拆分操作栏。 Whether to split is decided by the system at runtime 是否拆分由系统在运行时决定

You can define that the action bar should be automatically split by the system if not enough space is available you can activate this via the android:uiOptions="SplitActionBarWhenNarrow" parameter in the declaration of your application activity in the AndroidManifest.xml file. 如果没有足够的可用空间,您可以定义操作栏应由系统自动拆分,您可以通过AndroidManifest.xml文件中应用程序活动的声明中的android:uiOptions =“ SplitActionBarWhenNarrow”参数将其激活。

Doubtful. 疑。 However, you could se a combination of these when creating your menu items in the Action Bar to experiment. 但是,您可以在操作栏中创建菜单项进行实验时,将这些组合起来。

MenuItem.SHOW_AS_ACTION_ALWAYS
MenuItem.SHOW_AS_ACTION_NEVER
MenuItem.SHOW_IF_ROOM

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM