在顶部栏和底部栏上添加菜单项

3
在我的代码中,我希望在顶部操作栏上显示一些菜单项,而在底部栏上显示一些菜单项。我尝试使用分割操作栏,但是当我使用分割操作栏时,所有菜单项都设置为底部栏。那么我该如何在顶部栏上显示一些菜单项,在底部栏上显示一些菜单项呢?
2个回答

1
在您想要在底部显示的菜单项中添加android:showAsAction="never|withText"
如果您想要简单的底部菜单,请不要在清单中添加android:uiOptions="splitActionBarWhenNarrow",它只是帮助创建或添加底部菜单栏。

0
@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);

}

然后对于底部栏,我填充了我的菜单视图或任何您想要出现在底部的内容-

 @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;
}

Android清单文件-

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接